码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2016-09-03 06:18:22      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

[root@localhost 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
[root@localhost 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
[root@localhost wyb]# bash 2quan.sh 
Please Input a Username:cheng
This cheng is lock
[root@localhost 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
[root@localhost wyb]# bash 2quan.sh 
Please Input a Username:quit
input `quit`to quit
Pleas input a number:quit
[root@localhost wyb]# cat jing.log 
error
error
error
[root@localhost wyb]# cat cheng.log 
error
error
error
[root@localhost wyb]# 

 

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

标签:

原文地址:http://www.cnblogs.com/wangyuebo/p/5836088.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!