菜单栏:
脚本内容:
#!/bin/bash
function Enter() {
for q in {1..100}
do
read -p "请输入账号:" a
grep -h $a /root/www(用户及密码存放文件) >> /dev/null
if [ $? == 0 ]
then
echo "用户名正确"
for y in 1 2 3
do
read -p "请输入密码:" b
grep -h $a /root/www > /root/linshi(临时存放用户及密码文件)
grep -o $b /root/linshi >> /dev/null
if [ $? == 0 ]
then
echo "密码正确" && exit
elif [ $? -ne 0 ]
then
echo "密码错误"
fi
done
user=??? && echo "用户已锁定"
else
grep -h $a /root/www >> /dev/null
if [ $? == 0 ]
then
echo "用户名正确"
else
echo "用户名错误" && continue
fi
for n in {1..3}
do
read -p "请输入密码:" d
if [ $d == 0 ]
then
echo "密码正确" && exit
elif [ $d -ne 0 ]
then
echo "密码错误"
fi
done
user1=??? && echo "用户已被锁定"
fi
if [ $user == ??? ] && [ $user1 == ??? ]
then
exit
fi
done
}
function Login() {
read -p "请输入注册账号:" num
grep -o $num /root/www >> /dev/null
if [ $? == 0 ]
then
echo "此用户已存在"
else
read -p "请输入注册密码:" mmm
echo "$num:$mmm" >> /root/www
echo "用户创建成功"
fi
}
function Delete() {
read -p "请输入删除账户:" num
sed -i '/^'$num'/d' /root/www
if [ $? == 0 ]
then
echo "该用户已删除"
fi
}
function Exit() {
echo "已退出"
}
function menuitem() {
clear
cat << FOF
*************************
* *
* 1.Enter *
* 2.Login *
* 3.Delete *
* 4.Exit *
* *
*************************
FOF
read -p "请输入验证码:" p
case $p in
1)
Enter
;;
2)
Login
sleep 2
menuitem
;;
3)
Delete
sleep 2
menuitem
;;
4)
Exit
;;
*)
echo "请验证是否正确"
;;
esac
}
menuitem