Novell is now a part of Micro Focus

Using ldapsearch with LDIF Files

Novell Cool Solutions: Tip
By Jim Henderson

Digg This - Slashdot 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 -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:


then the search is performed three times, with these search filters:


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.

© Copyright Micro Focus or one of its affiliates