I want to check in a bash script that a specific organizationalunit with the given DN exists.
I'm doing an ldapsearch:
OU="ou=HQ,dc=myroot,dc=local"
ldapsearch -h localhost -b dc=myroot,dc=local -x -v "(&(objectClass=organizationalUnit)(dn="'"'$OU'"'"))"
and it always results in 0 even if the DN exists.
I have also tried:
ldapsearch -h localhost -b dc=myroot,dc=local -x -v "(&(objectClass=organizationalUnit)(dn=$OU))"
But the results are the same.
How can I do it? Is there a trick to the dn attribute?
Disregard that I'm using simple authentication.