Linux.com

Home Learn Linux Linux Answers Business Retrieve EMail address from Active Directory in a bash script

Favorite Favorite

Retrieve EMail address from Active Directory in a bash script

Author:
Andrea Benini
Date added:
Wednesday, 27 May 2009
Last revised:
never
Hits:
3017
Rating:
 
Vote for this:
Good - Bad
favoured:
0 Favour

Question Detail


Hi Everyone,

I need to create a script integrated with Samba that retrieves email addresses from given names, let me explain it better  ok ?

I've a Linux Machine into an Active Directory forest, i can get information for current AD usernames, something like:
myserver:~# wbinfo -i andrea
andrea:*:10014:10001:Andrea Benini:/home/DOMAIN/andrea:/bin/bash

I need to retrieve email address for the specified used, possibly using only bash scripts and utilities found in my system (AD integration through Samba+winbindd), is there a way to do it ?

Category

Tags for this Q & A

Answers  

 
#4 Andrea Benini 2009-08-31 23:05 I've now solved with PHP but Jesse solution is what I was looking for, nice trick :-)
 
 
+1 #3 Jesse Book 2009-08-19 21:31 Using the ldapsearch tool is a quick and easy way to pull information from AD.

the following command (substitute your directory info) can easily pull an email address from AD

ldapsearch -x -h -s sub -b dc=,dc=COM -D "CN=your id,DC=,DC=COM" -W '(&(objectclass=User)(givenName =firstname)(sn=lastname))' mail

wrapping the above in a shell script is trivial. use the command above and leave off 'mail' at the end. it should bring up all attributes that you can see.
 
 
#2 Andrea Benini 2009-06-04 17:35 found a link explaining capabilities of ldap-search package and various utilities but i think it's too limited, in my case I need to retrieve email address as well as other information from AD Tree, just solved using PHP. Of course Python and other folks can do the same as well
 
 
#1 Andrea Benini 2009-05-27 00:35 Forgot to mention a thing:
I've tried to get some info from AD with PHP and I can, is there a way to get something without installing the whole php-cli and libs ?

Thanks
Ben
 
Become an Individual Member

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Members / Staff / Board