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
....
....
....
Shahrukh Khan
  • 201
  • 2
  • 5
  • 10

2 Answers2

8

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).

Sobrique
  • 3,697
  • 2
  • 14
  • 34
  • 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 08 '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
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940