Question

using an OPENLDAP server i want to retrieve informations from it with ldapsearch. I created a custom class called iduriclass, this class is used to store an id and an uri. in my ldapsearch command i want it to return only the uri for a specified id.

EXAMPLE : the directory contain now two entries id=test uri=server.com/test and id=test2 uri=server.com/test2

Trying it i get an ldif file that contains all uris in the server

I want to have an ldapsearch command that takes test as argument and returns only a value that is : server.com/test

Was it helpful?

Solution

Here's how you query your ldap server.

HOSTNAME=<your ladap hostname>
USERNAME=<your ldap username>
PASSWORD=<your ldap username's password>
SEARCHBASE=<your ldap's search base DN>
QUERYSTRING=test1
PORT=<your ldap port>

ldapsearch -LLL -h ${HOSTNAME} -p $PORT -D cn=${USERNAME} -w ${PASSWORD} -b "${SEARCHBASE}" "(id=${QUERYSTRING})" uri | sed -n 's/^[ \t]*uri:[ \t]*\(.*\)/\1/p'

The option -LLL will not print ldap comments on output. Your ldap may require -x (simple authentication) if it doesn't support SASL.

OTHER TIPS

Adding the parameter -tt writes a file with ONLY the requested attribute(s) value as the OP requested. No preceding field name or anything else. Path is configurable with -T, otherwise is /tmp

I write this clarification due to lack of reputation to comment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top