Ldap – Using a file to store an ldapsearch query

ldap

I have to query attributes for about 10 000 users. I have an ldapsearch query that works for a single user. Here is the releveant part, where I search for the objectGUID attribute of user abc123 :

ldapsearch -h somehost.com -D "CN=valid_user,DC=valid_everything" -q -b "OU=valid_ou,DC=valid_dc" -s sub "cn=abc123" -L objectGUID 

I would like to put all my queries in a file, and use the -f myqueries.txt option. Since this query will be carried out over SSL, I would like to avoid the 10k SSL negotiations I would get if I was to run 10k separate ldapsearch.

I tried with a file that looks like this :

(cn=abc123)
(cn=lmn456)
(cn=xyz789)

With this modified command line :

ldapsearch -v -h somehost.com -D "CN=valid_user,DC=valid_everything" -q -b "OU=valid_ou,DC=valid_dc" -s sub -f myqueries.txt -L objectGUID 

But I always get an Bad search filter error.

I was not able to determine what version of ldapsearch this is. It is running on a custom Linux distribution.

How can I use the -f option to make ldapsearch use queries read from a file ?

Best Answer

File should look like this:

abc123
lmn456
xyz789

and command like this:

ldapsearch -v -h somehost.com -D "CN=valid_user,DC=valid_everything" -q -b "OU=valid_ou,DC=valid_dc" -s sub -f myqueries.txt "(cn=%s)" -L objectGUID 

File given after -f can only holds parameters of query, not the query.