5

I get list of all the users of LDAP using the following command ldapsearch -x -LLL uid=* > result.

The result of the following command results in following format

dn: uid=shahrukh,ou=People,dc=example,dc=com
uid: shahrukh
cn: shahrukh
sn: shahrukh
loginShell: /bin/bash
uidNumber: 1086
gidNumber: 1086
homeDirectory: /home/ldap/shahrukh

There is a complete list of these records.

I want to shortlist all the uid in one file such that only value of uid should be listed.

shahrukh
abc
xyz
....
....
....
7

You can specify attributes after your filter, and it will only display those attributes.

E.g.:

ldapsearch -x -LLL uid=* uid > result

This might give you a bunch of uid: 12345 lines. You might then have to pipe it through sed to remove the bit you don't want. (Alternatively, if you do it with perl and Net::LDAP you can extract precisely what you want - but I think ldapsearch + sed is the path of least resistance).

  • 1
    Agreed. I would do this: ldapsearch -x -LLL 'uid=*' uid | sed -n 's/^uid: // p'. That won't handle base64-encoded values (uid:: xxx), i.e. if some uid has non-printable or non-ascii characters, but I think you can fairly expect a uid to be ASCII only ;). – David Ammouial Oct 8 '15 at 21:04
0

The easiest way would be to pipe the results to grep and then cut. Example is

ldapsearch -x -LLL uid=* | grep uid: | cut -d: -f2 > results
  • 5
    Why use grep when you can just ask ldapsearch to give you the uid you want, as in the other answer? – Michael Hampton Dec 26 '18 at 21:33

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.