Ldap Script to get the details in minimal time Amit Srivastava: Difference between revisions
(Created page with "<center><u>'''''Ldap Script to get the details of user with location parameter'''''</u></center> <center><u>''We can add any parameter to search this will consume few second...") |
No edit summary |
||
Line 14: | Line 14: | ||
<nowiki># Start of the script </nowiki> | <nowiki># Start of the script </nowiki> | ||
<nowiki># Reference https://wiki.zimbra.com/wiki/ShanxT-LDAP-CheatSheet </nowiki> | |||
source ~/bin/zmshutil | source ~/bin/zmshutil |
Revision as of 07:42, 2 October 2015
Script Name: get_list_by_ldap.sh
#!/bin/bash
# Made By Amit Srivastava
# Use this script from zimbra user
# Start of the script
# Reference https://wiki.zimbra.com/wiki/ShanxT-LDAP-CheatSheet
source ~/bin/zmshutil
zmsetvars
tmpoutfile=”/tmp/Amit/uidlist.txt”
rm -vf $tmpoutfile
#initially remove any tmp file if exist.
ldapsearch -x -H $ldap_master_url -D $zimbra_ldap_userdn -w $zimbra_ldap_password -LLL '(&(objectClass=zimbraAccount)(uid=*))' | grep -w uid:> $tmpoutfile
# Above will list the all uid present in zimbra
sed -i 's/uid: /uid=/g' $tmpoutfile
# Above is modifying the ldap search parameter to have the proper input in ldapsearch (replacing uid: by udi=)
echo "Email_ID's Account_Status Branch" >> $tmpoutfile
echo "------------------------------------------------" >> $tmpoutfile
# Below is the starting of the loop which looks from the temprary output file store the values in variable and then have the output accordingly
for i in `cat $tmpoutfile`
do
j="(&(objectClass=zimbraAccount)("$i"))"
Email_ID=$i
Account_Status=`ldapsearch -x -H $ldap_master_url -D $zimbra_ldap_userdn -w $zimbra_ldap_password -LLL $j | grep -w zimbraAccountStatus| cut -d: -f2`
Branch=`ldapsearch -x -H $ldap_master_url -D $zimbra_ldap_userdn -w $zimbra_ldap_password -LLL $j | grep -w l:| cut -d: -f2`
echo "$Email_ID $Account_Status $Branch ">> $tmpoutfile
done
# Script Finished