脚本接受参数,恢复或者禁止指定用户登录
代码:
#!/bin/bash
if [ -z $1 ]; then
echo "please input e or d.e is enable,d is disable!"
exit 1
elif [ $1 == "e" ] || [ $1 == "d" ]; then
act=$1
else
echo "input error!please input e or d.e is enable,d is disable!"
echo $1
exit 1
fi
if [ -z $2 ]; then
echo "please input one username"
exit 1
else
username=$2
fi
j=$(grep ${username}":" /etc/passwd|wc -l)
u=$(egrep "^${username}:" /etc/passwd|cut -d ":" -f3)
#echo $u
#exit 0
if [ $j -eq 0 ]; then
echo "user not exist!"
exit 1
else
if [ $u -eq 0 ]; then
echo "please input another username!"
exit 1
else
if [ $act == "d" ]; then
echo $username " can not login"
usermod -s /usr/sbin/nologin $username
elif [ $act == "e" ]; then
echo $username "can login"
usermod -s /bin/bash $username
fi
fi
fi