2

I'm trying to do a search on my LDAP base like that:

ldapsearch  -x -h localhost -p 389 -D uid=xxxadmin,ou=administrators,ou=topologymanagement,o=netscaperoot -v -w 12345 -b "ou=Usuarios,ou=Alunos,ou=XXXX,o=xxXXXxx" -f (!(objectClass=ntUser)) 1.1

Basically I want to list all the entries without the objectClass ntUser and add the objectClass to them.

I'm getting this as an answer:

-bash: !: event not found
Ocaso Protal
  • 19,362
  • 8
  • 76
  • 83
ledesma
  • 248
  • 1
  • 7
  • 18
  • 2
    That's not a problem with your filter/parameter but with bash. Wrap the filter in single quotes `'` and it should work. – Ocaso Protal May 18 '15 at 14:36

3 Answers3

3

From http://www.openldap.org/lists/openldap-software/200104/msg00196.html

This message comes from the shell (bash). It states that the command `!' didn't find the event you unintentionally asked for. This happens because the double quotes in bash do not prevent some command invocation. Use single quotes instead:

Your search should be like this:

ldapsearch  -x -h localhost -p 389 -D 'uid=xxxadmin,ou=administrators,ou=topologymanagement,o=netscaperoot' -v -w 12345 -b 'ou=Usuarios,ou=Alunos,ou=XXXX,o=xxXXXxx' -f '(!(objectClass=ntUser))' 1.1
0

Your search should work. But, for bash, you will need to quote the parameters.

Something like:

ldapsearch  -x -h localhost -p 389 -D uid=xxxadmin,ou=administrators,ou=topologymanagement,o=netscaperoot -v -w 12345 -b "ou=Usuarios,ou=Alunos,ou=XXXX,o=xxXXXxx" -f "(!(objectClass=ntUser))" 1.1

Tested both openLDAP

@(#) $OpenLDAP: ldapsearch  (Ubuntu) (Mar 17 2014 21:19:27) $buildd@aatxe:/build/buildd/openldap-2.4.31/debian/build/clients/tools
(LDAP library: OpenLDAP 20431)

ldapsearch -x -h localhost -p 389 -D "cn=admin" -W -b "dc=example,dc=com" -s sub -a always -z 1000 "(!(objectClass=inetOrgPerson))" "objectClass"

and OpenDJ

ldapsearch --version
        OpenDJ 2.7.0-20140727
        Build 20140727000040Z

ldapsearch -h localhost -p 389 -D "cn=admin" -b "dc=example,dc=com" -s sub -a always -z 1000 "(!(objectClass=inetOrgPerson))" "objectClass"

-jim

jwilleke
  • 10,467
  • 1
  • 30
  • 51
  • still have the same problem..any other search works.. only when I'm using "!" it's not working. – ledesma May 22 '15 at 11:27
0

Its happening because bash thinks ! as a special character

"!" Start a history substitution, except when followed by a space, tab, the end of the line, ‘=’ or ‘(’

So finally, you should be able to solve your problem by putting single quotes around the term as follow:

ldapsearch  -x -h localhost -p 389 -D uid=xxxadmin,ou=administrators,ou=topologymanagement,o=netscaperoot -v -w 12345 -b "ou=Usuarios,ou=Alunos,ou=XXXX,o=xxXXXxx" -f '(!(objectClass=ntUser))' 1.1

Please refer following question on stackoverflow.

Which characters need to be escaped in Bash? How do we know it?

Community
  • 1
  • 1
chetan pawar
  • 485
  • 3
  • 9