using ldapsearch to return only a value using ldapsearch to return only a value linux linux

using ldapsearch to return only a value


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=test1PORT=<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.


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.