Log in


Forgot your password?
prijatelji LUGoNSa
gnu.gif
linuxzasve.jpg
hulk.jpg
zextras_logo.png
 
You are here: Home / Uputstva / Opšte / Skripte / LDAP / delUser.sh

delUser.sh

by lugons last modified Apr 22, 2008 12:43 PM

text/x-sh icon delUser.sh — text/x-sh, 569 bytes

File contents

#!/bin/bash

if [ $# -lt 1 ]; then
	echo "Usage: $0 <user>@<domain>"
	exit 1
fi

USER=`echo "$@" | cut -f 1 -d '@'`
DOMAIN=`echo "$@" | cut -f 2 -d '@'`

read -p "Enter the LDAP password: " -s PASSWORD
echo

function deleteDomain()
{
	DOMAINS=`ldapsearch -LLL -x "(objectClass=person)" ou | grep $DOMAIN`
	if [ -z "$DOMAINS" ]; then
		echo "Removing empty domain..."
		ldapdelete -w "$PASSWORD" -x -D "cn=root,dc=ldap" "ou=$DOMAIN,dc=ldap"
	fi
}

ldapdelete -w "$PASSWORD" -x -D "cn=root,dc=ldap" "uid=$USER,ou=$DOMAIN,dc=ldap"
if [ "$?" = "0" ]; then
	deleteDomain
fi

Document Actions