The output from ldapsearch is sent to stdout as LDIF (LDAP Interchange Format). The format is reasonably readable, but not very flexible. In particular, lines longer than 78 characters are split, with the following line starting with a space. In many cases it is necessary to post-process the output to make it more readable. To obtain the output in single line one useful trick is that piping the LDIF through perl will undo the line splitting mentioned above (lines starting with a space are joined to the previous line). Use the following command of perl to undo the splitting.

perl -p00e ‘s/\r?\n //g’

Here is an example for the above

Default LDAP search:

ldapsearch -b "ou=ag-BDC8DE1582A8FE05, ou=AppliancesContainer, ou=Partition, ou=PartitionsContainer, ou=VCDN_ROOT, ou=accessManagerContainer, o=novell" -s sub -D cn=admin,o=novell" -x -w novell -s base romaAssociation –LLL

Output:

dn: ou=ag-BDC8DE1582A8FE05,ou=AppliancesContainer,ou=Partition,ou=PartitionsCo
 ntainer,ou=VCDN_Root,ou=accessManagerContainer,o=novell
romaAssociation: ou=3f3822a238615338,ou=ApplianceGroupContainer,ou=Partition,o
 u=PartitionsContainer,ou=VCDN_Root,ou=accessManagerContainer,o=novell#1#romaA
 pplianceGroup
 

In the above we can see output is seen in separated lines with each of 78 characters.

LDAP search piping to perl will get output in a single line for the attribute values.

ldapsearch -b "ou=ag-BDC8DE1582A8FE05, ou=AppliancesContainer, ou=Partition, ou=PartitionsContainer, ou=VCDN_ROOT, ou=accessManagerContainer, o=novell" -s sub -D "cn=admin,o=novell" -x -w novell -s base romaAssociation -LLL | perl -p00e 's/\r?\n //g'
dn: ou=ag-BDC8DE1582A8FE05,ou=AppliancesContainer,ou=Partition,ou=PartitionsContainer,ou=VCDN_Root,ou=accessManagerContainer,o=novell
romaAssociation: ou=3f3822a238615338,ou=ApplianceGroupContainer,ou=Partition,ou=PartitionsContainer,ou=VCDN_Root,ou=accessManagerContainer,o=novell#1#romaApplianceGroup

The output of above can be directly used as input to other applications because of single line output.

0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0 votes, average: 0.00 out of 5)
You need to be a registered member to rate this post.
Loading...Loading...
Categories: Uncategorized

Disclaimer: As with everything else at NetIQ Cool Solutions, this content is definitely not supported by NetIQ, so Customer Support will not be able to help you if it has any adverse effect on your environment.  It just worked for at least one person, and perhaps it will be useful for you too.  Be sure to test in a non-production environment.

Leave a Reply

Leave a Comment

By: sashwin
Oct 27, 2010
3:42 pm
Reads:
5,464
Score:
Unrated