Linux 脚本----用户脚本作业
#!/bin/bash
#zxs
#用户管理
while true
do
echo "
//==============================\\
| 用户管理系统 |
----------------------------------
| 1、创建用户 |
| 2、删除用户 |
| 3、锁定用户 |
| 4、解锁用户 |
| 5、查看用户 |
| 6、退出脚本 |
----------------------------------
"
#编制
read -p "请输入你的操作选择" number
#建立用户
if [ $number = 1 ]
then read -p "创建用户名:" user
cat /etc/passwd | grep $user &> /dev/null
if [ ! $? = 0 ]
then useradd $user &> /dev/null && echo "创建成功。"
else echo "用户已存在。"
fi
#删除用户设置
elif [ $number = 2 ]
then read -p "输入删除用户:" user
cat /etc/passwd | grep $user &> /dev/null
if [ $? = 0 ]
then userdel $user &> /dev/null && echo "删除用户成功。"
else echo "用户不存在,无法删除。"
fi
#锁定用户
elif [ $number = 3 ]
then read -p "输入锁定用户名:" user
cat /etc/passwd | grep "$user" &> /dev/null
if [ $? = 0 ]
then passwd -l $user && echo "用户已锁定。"
else echo "用户不存在,无法锁定。"
fi
#解锁用户
elif [ $number = 4 ]
then read -p "输入解锁的用户:" user
cat /etc/passwd | grep "$user" &> /dev/null
if [ $? = 0 ]
then passwd -f -u $user && echo "用户已解锁。"
else echo "用户不存在,无法解锁。"
fi
#查看用户设置
elif [ $number = 5 ]
then read -p "输入查看的用户:"
cat /etc/passwd | grep "$user" &> /dev/null
if [ $? = 0 ]
then cat /etc/passwd | grep "$user"
else echo "查看用户不存在。"
fi
#退出设置
elif [ $number = 6 ]
then echo "退出登陆。" && break
fi
done