1

I wish to count the number of objects returned from a query (but I do not need the actual objects themselves) from Sun Java System Directory Server 5.2.

E.g., if I want to find all people with surname Smith, I would want something like

ldapsearch -LLL -H ldaps://example.com -b "ou=people,dc=example,dc=com" "sn=Smith"

but with some sort of count. Is this possible without returning all of the results?

1
  • Not a direct answer, but you could just ask for 'dn' to be returned, reducing the size of the response.
    – Joe H.
    Mar 5 '12 at 15:09
3

Either append the ldapentrycount option to the end:

ldapsearch -LLL -H ldaps://example.com -b "ou=people,dc=example,dc=com" "sn=Smith" ldapentrycount

or parse the numEntries value from the results:

ldapsearch -LLL -H ldaps://example.com -b "ou=people,dc=example,dc=com" "sn=Smith" ldapentrycount | awk '/numEntries: / { print $3 }'

Is this what you're looking for?

0

One word of caution -- you can count the number of objects returned from the query, but that may not be the same as the number of objects matched, as there may be limits on the number of objects returned. You can add -z 0 to try to remove a soft limit.

I'd personally go with something like:

ldapsearch -LLL -z 0 -H ldaps://example.com -b "ou=people,dc=example,dc=com" "sn=Smith" dn | grep ^dn: | wc -l
3
  • Even with removing the soft limit, I get 11: Administrative limit exceeded. Mar 5 '12 at 15:50
  • @cubetwo1729 : You might have a different limit if you also send authentication information. It's been years since I've done admin work for a Sun Directory server (shortly after they went from iPlanet to SunOne), but I seem to remember having set up a dn to bind as for searching that had higher limits.
    – Joe H.
    Mar 5 '12 at 16:10
  • 1
    "administrative limit exceeded" on DSEE means the client has exceeded the lookthroughlimit, which is a server-side limit on the number of entries the server will examine when constructing the candidate list of entries that match the query. Aug 24 '12 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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