BBS水木清华站∶精华区
发信人: sjhuang@csie.nctu.edu.tw (chauffeur), 信区: Linux
标 题: adduser & deluser
刚刚才知道 debian 有 adduserutil,也是用shell script 写的.
前几篇有人问deluser,贴一下 deluser:
作者考虑到 homedir,passwd entry,还有 mail spool,至於 crontab 就可以参考他
砍 mail spool 的地方...
[板主 mglow 注]
此法对有装 shadow password 的系统无效...
===========================================================================
#!/bin/sh
# Primitive attempt to provide a facilty to erase users from /etc/passwd
# etc.
# Christoph Lameter, 24. September 1996
if [ "$1" = "" ]; then
echo -e "Usage: deluser <userid>\n"
exit 1;
else
if grep -q "^$1:" /etc/passwd; then
if [ -f /etc/ptmp ]; then
echo "/etc/passwd locked (/etc/ptmp)."
exit 2
fi
touch /etc/ptmp
HOMEDIR=`awk -F: "/^$1:/ { print \$6 }" </etc/passwd`
if "$HOMEDIR" = ""; then
echo "Homedirectory not valid!";
else
rm -rf $HOMEDIR
fi
rm /var/spool/mail/$1 2>/dev/null
cp /etc/passwd /etc/passwd~
sed -e "/^$1:/d" </etc/passwd~ >/etc/passwd
rm /etc/ptmp
echo "User $1 removed"
if grep -q $1 /etc/group; then
echo "References to user $1 remaining in
/etc/group!"
fi
else
echo "User $1 not in /etc/passwd"
fi
fi
====================================================================
BBS水木清华站∶精华区