Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 -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 :


With this modified command line :

ldapsearch -v -h -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 ?

share|improve this question
up vote 2 down vote accepted

File should look like this:


and command like this:

ldapsearch -v -h -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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.