6

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

2 Answers2

9

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,817
1

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
  • 252,907