Ldap Script to get the details in minimal time Amit Srivastava

Revision as of 07:44, 2 October 2015 by Amit Srivastava (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Ldap Script to get the details of user with location parameter


We can add any parameter to search this will consume few seconds only to search the expected result


Script Name: get_list_by_ldap.sh

#!/bin/bash

# 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

Jump to: navigation, search