5

How would I make a bourne shell code for a LDAP search to not return DN and return only CN? I am using iTerm2 for this.

Claudiu Kiss
  • 63
  • 1
  • 3
  • I have tried using cn filter to show the cn, but I can't find anything about removing the DN return. I have tried --searchScope one, but it won't return anything. – Claudiu Kiss Sep 01 '15 at 13:10
  • You need to show what the LDAP output looks like. – glenn jackman Sep 01 '15 at 13:35
  • dn: uid=zsarour,ou=august,ou=2013,ou=paris,ou=people,dc=42,dc=fr dn: uid=zcarde,ou=august,ou=2014,ou=paris,ou=people,dc=42,dc=fr Something like this, only there are a lot more of them. – Claudiu Kiss Sep 01 '15 at 13:37

1 Answers1

7

If you only want to see the cn results, then you can use something like:

ldapsearch -o ldif-wrap=no -L <blah> cn | grep '^cn:'

where <blah> is your bind/search conditions

the reason it returns the dn is because the returned data would not be properly formed ldif without it.

By using -o ldif-wrap=no you don't have to cope with issues involving line-wrapping of the returned data.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • Use the _exclude_ notation of grep, to exclude the dn, then the Right Side of the command stays constant and additional attributes can be added to the Left Side. `ldapsearch -o ldif-wrap=no -LLL mail | grep -v -E '(^$|dn:)'` – alls0rts Dec 03 '20 at 11:30