Delete user

Duan Zhenhai (ccdzh@shoukui.pku.edu.cn)
Wed, 18 Dec 1996 09:47:23 +0900 (JST)


Hi,

I had written a shell to delete one user. But I do not know
if I had done what all I should do to delete user.

Any comment is appreciated.
Please send directly to me, Now I am not on this list.

ccdzh@pku.edu.cn

Duan Zhenhai
Peking University

//////////////////////////////////////////////////////////////////////////
#!/bin/bash
#
#delete the user your give.
#deluser username
#ccdzh@pku.edu.cn
#

if [ $# -ne 1 ]; then
echo "Usage: $0 user_account_you_want_to_delete"
exit 1
fi

#
#delete the user home directory
#

if [ -d /home/$1 ]; then
rm -r /home/$1
echo delete the /home/$1
else
echo No such user
exit 1
fi

#
#modify the passwd file
#

grep -v "^$1:" /etc/passwd > /tmp/passwd.tmp
mv /tmp/passwd.tmp /etc/passwd
echo delete the item in the /etc/passwd

#
#delete the user's system mailbox
#

if [ -f /usr/spool/mail/$1 ]; then
rm /usr/spool/mail/$1
echo delete the user system mailbox
fi

#
#done
#