I am trying to echo out every user on LDAP onto one text file but with a custom format:
The end goal is to have the following format:
So an example would be:
jdoe=John Doe <firstname.lastname@example.org> jdoe1=Jane Doe <email@example.com> ...
I'm currently doing the following in terminal (Ubuntu 14.04):
echo `ldapsearch -x -h 127.0.0.1 -b "dc=company,dc=com" uid=* cn mail` >> ldap-users.txt
Which is getting everything I need however the format is as follows:
# extended LDIF # # LDAPv3 # base <dc=company,dc=com> with scope subtree # filter: uid=* # requesting: cn mail # # jdoe, Special Users, company.com dn: uid=jdoe,ou=Special Users,dc=company,dc=com cn: John Doe User mail: firstname.lastname@example.org # jdoe1, People, company.com dn: uid=jdoe1,ou=People,dc=company,dc=com cn: Jane Doe mail: email@example.com # ....... # search result search: 2 result: 0 Success # numResponses: 1387 # numEntries: 1386
NOTE: That that's all spit out in one line.
Any help is appreciated,
EDIT: So by researching more I found out I can do:
ldapsearch -LLL -x -h 127.0.0.1 -b "dc=covisint,dc=com" uid=* cn mail
Which by adding -LLL it will not print ldap comments on output. Which results in the following format:
dn: uid=jdoe,ou=Special Users,dc=company,dc=com cn: John Doe User mail: firstname.lastname@example.org ................... dn: blahblahblha... etc
So that helps alot, now if there's a way to remove the "uid=" and the ",ou=...,dc=company,dc=com" and "cn:" and "mail:"