[[email protected] wyb]# cat 2quan.sh #!/bin/bash #写一个脚本,先要求输入用户名,然后让他输入一个数字,输的如果是数字给输出yes,不是数字,输出no #然后如果输入三次以上不是数字锁定此用户,就是不能让他上了 #要求次数累加,即使关了脚本再重启,也没用,依旧锁定,次数到了3就锁定 read_user() { read -p "Please Input a Username:" username } read_user while [ -z $username ] do read_user done [ ! -f $username.log ] && touch $username.log judge_user() { key=`cat $username.log|wc -l` [ $key -ge 3 ] && echo "This $username is lock" && exit } judge_user echo ‘input `quit`to quit‘ while : do judge_user read -p "Pleas input a number:" num [ -z $num ] && continue [[ "$num" = "quit" ]] && break expr $num + 1 &>/dev/null [ $? -ne 0 ] && echo error >> $username.log && echo no|| echo yes done [[email protected] wyb]# bash 2quan.sh Please Input a Username:cheng input `quit`to quit Pleas input a number:eee no Pleas input a number:123 yes Pleas input a number:123 yes Pleas input a number:ddd no Pleas input a number:aaa no This cheng is lock [[email protected] wyb]# bash 2quan.sh Please Input a Username:cheng This cheng is lock [[email protected] wyb]# bash 2quan.sh Please Input a Username:jing input `quit`to quit Pleas input a number:123 yes Pleas input a number:bbb no Pleas input a number:ddd no Pleas input a number:aaa no This jing is lock [[email protected] wyb]# bash 2quan.sh Please Input a Username:quit input `quit`to quit Pleas input a number:quit [[email protected] wyb]# cat jing.log error error error [[email protected] wyb]# cat cheng.log error error error [[email protected] wyb]#
时间: 2024-09-29 00:55:52