Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Readable ldapsearch output

by brx (Pilgrim)
on Apr 06, 2012 at 11:21 UTC ( #963814=CUFP: print w/ replies, xml ) Need Help??

*update* : simplification with xx_XX.UTF-8 "locale" (see below)

When you are using ldapsearch to find quickly some informations in LDAP directory, there are some problems.

  1. Some lines are wrapped (several lines for a single attribute-value).
  2. Some lines are encoded in base64 (those with utf8 content).

For instance, with this command :

ldapsearch -x -LLL -h myldaphost -b 'ou=myldapbase,...'

Just "pipe" the result in this Perl filter :

ldapsearch ... | perl -MMIME::Base64 -MEncode=decode -n -00 -e 's/\n +//g;s/(?<=:: )(\S+)/decode("UTF-8",decode_base64($1))/eg;print' [or] ldapsearch ... | perl -MMIME::Base64 -MEncode=decode -n -00 -e 's/\n +//g;s/(?<=:: )(\S+)/decode("UTF-8",decode_base64($1))/eg;print if /Be +yoncé/'

This way, the Lord of the Rings can see the entire block (LDAP entry) matched by the regex you want (a single lady, in this example).

Warning : the output is NOT LDIF-compatible, it's just 'text'.


update : depending of your context (locale with or without UTF-8), you can simplify the command-line, like this:

ldapsearch ... | perl -MMIME::Base64 -n -00 -e 's/\n //g;s/(?<=:: )(\ +S+)/decode_base64($1)/eg;print' [or] ldapsearch ... | perl -MMIME::Base64 -n -00 -e 's/\n //g;s/(?<=:: )(\ +S+)/decode_base64($1)/eg;print if /Beyoncé/'

Comment on Readable ldapsearch output
Select or Download Code
Re: Readable ldapsearch output
by i5513 (Monk) on Apr 06, 2012 at 17:09 UTC

    There was a patch propposed to add --ldif-wrap (and solve your first point, but it was not accepted (seems like it is really not a bug)).

    Too, there is a bug (archived), where there is a request to add a similar perl script to documentation.

Re: Readable ldapsearch output
by Anonymous Monk on Jul 25, 2013 at 00:46 UTC
    Thank you for this
Re: Readable ldapsearch output
by Anonymous Monk on Sep 09, 2013 at 19:25 UTC
    THANK YOU!!! It worked immediately, no hacking required.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://963814]
Approved by Corion
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-08-20 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (124 votes), past polls