ltcp/aufgabe3.5/ldap-tools/ldap-delete-users

40 lines
672 B
Plaintext
Raw Normal View History

2013-11-14 11:45:22 +00:00
#!/bin/sh
# check for root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# check for arguments
if [[ $# -gt 1 ]]; then
echo "USAGE: $0 [filename]" 1>&2
exit 1
fi
SECRET="`cat /etc/ldap.secret`"
if [[ $# -eq 1 ]]
then
exec < $1
fi
cd /home
while read line
do
if [[ -z $line ]]
then
continue
fi
line="`echo $line | cut -d ' ' -f 1`"
2013-11-14 11:45:22 +00:00
echo "Deleting user ${line}..."
ldapdelete -x -w "$SECRET" -D cn=admin,dc=zotac,dc=lctp "cn=$line,ou=users,dc=zotac,dc=lctp" >/dev/null
ldapdelete -x -w "$SECRET" -D cn=admin,dc=zotac,dc=lctp "cn=$line,ou=groups,dc=zotac,dc=lctp" >/dev/null
[ -d "$line" ] && rm -rf "$line"
done