Using ldapsearch with LDIF Files
Novell Cool Solutions: Tip
By Jim Henderson
Digg This -
Posted: 19 Apr 2006
"I've used the LDAP command-line utilities in the past to add and modify objects using LDIF files. The ldapsearch.exe utility has a -f option, so it must be able to use an input file. But I am unable to figure out the correct LDIF syntax, or find any examples to make it work.
Basically, I want to search for the existence of a list of Surnames that will be in the LDIF file, and output the associated cn's if that surname exists. Has anyone done anything similar to this? If so, could you post a portion of the LDIF file you used?"
And here's the response from eDirectory expert Jim Henderson:
The way this works is that you create a file that has one entry per line for the surnames you're looking for. Then you execute the following, all on one line:
ldapsearch -h 172.16.0.25 -p 389 -ZZ -f filename.txt -b o=home -s sub -x -D cn=jim,o=home -W "(sn=%s)" cn
The lines in filename.txt are read one by one, and the value found is inserted where %s is in the search filter. So, if the file filename.txt contains:
Henderson Smith Parker
then the search is performed three times, with these search filters:
"(sn=Henderson)" "(sn=Smith)" "(sn=Parker)"
The results are output to wherever you've pointed the destination at (in the above command-line example, it would be to the console).
Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com