#!/usr/bin/perl # Pass username to the script on the command line and # receive an email address in return # From Perl Ldap-0.39 website. Modified by Campbell McKenzie # cam mckenzie gmail com # For use in AIX Password Expiration Notification Script # http://www.cammckenzie.com # REQUIRES: Perl Ldap Libs and Convert-ASN Libs use lib '/cable/scripts/lib/Convert-ASN1-0.22/lib'; ## -Change This Line- use lib '/cable/scripts/lib/perl-ldap-0.39/lib'; ## -Change This Line- use Net::LDAP; if ($ARGV[0] eq '') { print "Require username on command line. Exiting.\n"; exit; } $USERNAME = $ARGV[0]; $ldap = Net::LDAP->new( 'YOURDOMAIN.CONTROLLER.COM' ) or die "$@"; ## -Change This Line- # bind to a directory with dn and password # Full DN of a user account to access AD $mesg = $ldap->bind( 'CN=SOMEUSER,OU=Users,DC=YOURDOMAIN,DC=com', ## -Change This Line- password => 'ACCOUNTPASSWORDGOESHERE' ## -Change This Line- ); $mesg = $ldap->search( # perform a search - return only mail attr base => "DC=YOURDOMAIN,DC=com", ## -Change This Line- filter => "(&(sAMAccountName=$USERNAME))", attrs => ['mail'] ); $mesg->code && die $mesg->error; foreach $entry ($mesg->entries) { $entry->dump; } $mesg = $ldap->unbind; # take down session