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?

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

2 Answers2

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?

quanta
  • 51,413
  • 19
  • 159
  • 217
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
Joe H.
  • 1,917
  • 12
  • 13
  • Even with removing the soft limit, I get 11: Administrative limit exceeded. – cubetwo1729 Mar 05 '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 05 '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. – Terry Gardner Aug 24 '12 at 07:01