Sorry for the delay, but I had to install and populate an LDAP server first to test the correct procedure. As ldapdelete
reads the list of objects from STDIN if there are none presented on the command line (or in a file), you can use a pipe like
ldapsearch -ZZ -W -D 'cn=Manager,dc=site,dc=fake' \
-b 'ou=people,dc=site,dc=fake' -s one dn |\
grep dn: | cut -b 5- | ldapdelete -ZZ -W -D 'cn=Manager,dc=site,dc=fake'
This will ask you for the password twice; maybe you can use some other authentication method.
Instead of -b ... -s one
you might have to define some other search base/scope/filter, depending on the directory structure.
I leave the part grep dn: | cut -b 5- |
for those of you familiar to awk/sed/... any other constructs to optimize. I just like to keep things simple.
ldapsearch
and pipe it toldapdelete
(without-r
option).