首页 > 代码库 > shelll脚本,常见的脚本题目。

shelll脚本,常见的脚本题目。

[root@localhost wyb]# cat 2quan.sh #!/bin/bash#写一个脚本,先要求输入用户名,然后让他输入一个数字,输的如果是数字给输出yes,不是数字,输出no#然后如果输入三次以上不是数字锁定此用户,就是不能让他上了#要求次数累加,即使关了脚本再重启,也没用,依旧锁定,次数到了3就锁定read_user(){read -p "Please Input a Username:" username}read_userwhile [ -z $username ]do    read_userdone[ ! -f $username.log ] && touch $username.logjudge_user(){   key=`cat $username.log|wc -l`   [ $key -ge 3 ] && echo "This $username is lock" && exit}judge_userecho input `quit`to quitwhile :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 yesdone[root@localhost wyb]# bash 2quan.sh Please Input a Username:chenginput `quit`to quitPleas input a number:eeenoPleas input a number:123yesPleas input a number:123yesPleas input a number:dddnoPleas input a number:aaanoThis cheng is lock[root@localhost wyb]# bash 2quan.sh Please Input a Username:chengThis cheng is lock[root@localhost wyb]# bash 2quan.sh Please Input a Username:jinginput `quit`to quitPleas input a number:123yesPleas input a number:bbbnoPleas input a number:dddnoPleas input a number:aaanoThis jing is lock[root@localhost wyb]# bash 2quan.sh Please Input a Username:quitinput `quit`to quitPleas input a number:quit[root@localhost wyb]# cat jing.log errorerrorerror[root@localhost wyb]# cat cheng.log errorerrorerror[root@localhost wyb]# 

 

shelll脚本,常见的脚本题目。