[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 ] && 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 + &>/dev/null
[ $? -ne ] && 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:
yes
Pleas input a number:
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:
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]#

增加了一些需求

#写一个脚本,先要求输入用户名,然后让他输入一个数字,输的如果是数字给输出yes,不是数字,输出no
#然后如果输入三次以上不是数字锁定此用户,就是不能让他上了
#要求次数累加,即使关了脚本再重启,也没用,依旧锁定,次数到了3就锁定
#如果用户被锁,则提示用户问他是不是解锁
#解锁的话需要输入5次数字,有一次错误都不能解锁,如果输入5次都没错,那么用户解锁
#增加注册与登录。如果登录的用户没有注册,则提示注册,如果登录用户已注册,则可以继续操作
[root@localhost wyb]# cat 12quan.sh
#!/bin/bash
read_user()
{
read -p "Please Input username:" username
}
flag=
read_user
while [ -z $username ]
do
read_user
done
user_reg()
{
echo ----------------create a user--------------
read -p "Please Input A username:" name1
[ -z $name1 ] && echo "You Do no Input" && exit
read -p "Please Input A username:" name2
[ -z $name2 ] && echo "You Do no Input" && exit
[[ "$name1" = "$name2" ]] && echo $name1 >> user.list
echo "Your user ($name1) has registered!" && exit }
#注册了flag2不变是0可以执行程序
flag2= [ ! -f ${username}.log ] && touch ${username}.log
[ ! -f user.list ] && touch user.list
user_exist=`cat user.list|grep -c "\<$username\>"`
[ $user_exist -eq ] && read -p "You username do not exist.create it(yes/on)?" create_user && flag2=
#[ "$create_user" = "no" ] && exit
[ $flag2 -eq ] && [[ "$create_user" = "yes" ]] && user_reg
[ $flag2 -eq ] && exit
unlock_user()
{
for i in `seq - `
do
read -p "Please a number(remain $i counts):" unlock_num
expr $unlock_num + &>/dev/null
[ $? -ne ] && echo "Input error,unlock stop" && exit
done
echo "( $username ) has been unlocked"
> ${username}.log
}
judge_user()
{
key=`cat ${username}.log|wc -l`
[ $key -ge ] && echo "Your username ( $username ) is locked." && flag=
[ $flag -eq ] && read -p "Do you wanna to unlock(yes/no)" unlock_key
[ $flag -eq ] && [[ "$unlock_key" = "yes" ]] && unlock_user && exit
[ $flag -eq ] && [[ "$unlock_key" != "yes" ]] && exit
}
judge_user
echo 'Input `quit` to quit'
while :
do
judge_user
read -p "Please Input a number:" number
[ -z $number ] && continue
[[ "$number" = "quit" ]] && break expr $number + &>/dev/null
[ $? -ne ] && echo "error" >> ${username}.log && echo no || echo yes
done [root@localhost wyb]# bash 12quan.sh
Please Input username:aaa
You username do not exist.create it(yes/on)?yes
----------------create a user--------------
Please Input A username:aaa
Please Input A username:aaa
Your user (aaa) has registered!
[root@localhost wyb]# bash 12quan.sh
Please Input username:aaa
Input `quit` to quit
Please Input a number:
yes
Please Input a number:
yes
Please Input a number:no
no
Please Input a number:no
no
Please Input a number:no
no
Your username ( aaa ) is locked.
Do you wanna to unlock(yes/no)yes
Please a number(remain counts):
Please a number(remain counts):
Please a number(remain counts):
Please a number(remain counts):
Please a number(remain counts):
( aaa ) has been unlocked
[root@localhost wyb]# bash 12quan.sh
Please Input username:aaa
Input `quit` to quit
Please Input a number:
[root@localhost wyb]#

shelll脚本,常见的脚本题目。的更多相关文章

  1. 脚本AI与脚本引擎

    Scripted AI and Scripting Engines 脚本AI与脚本引擎 This chapter discusses some of the techniques you can us ...

  2. iOS面试中常见的算法题目

    一.前言 这里是在iOS求职中自己遇到的算法题,希望对大家有所帮助.不定期更新.如果大家想在线运行代码调试,可以将代码拷贝到这里.然后进行调试.下面就是常见的算法题目. 二.正文 1.就n的阶乘.(这 ...

  3. centos shell编程6一些工作中实践脚本 nagios监控脚本 自定义zabbix脚本 mysql备份脚本 zabbix错误日志 直接送给bc做计算 gzip innobackupex/Xtrabackup 第四十节课

    centos   shell编程6一些工作中实践脚本   nagios监控脚本 自定义zabbix脚本 mysql备份脚本 zabbix错误日志  直接送给bc做计算  gzip  innobacku ...

  4. unity中js脚本与c#脚本互相调用

    unity中js脚本与c#脚本互相调用   test1.js function OnGUI() { if(GUI.Button(Rect(25,25,100,30),"JS Call CS& ...

  5. JavaScript值延迟脚本和异步脚本

    Html 4.0为<script>标签定义了defer属性,这个属性的用途是表名脚本在执行时,不会影响页面的构造.也就是说,脚本会延迟到整个页面解析完毕之后在运行,因此,在<scri ...

  6. tcl脚本直接执行脚本中中文识别不了的处理

    上一篇说tcl中文乱码是因为我写了个bat调用该脚本,但是脚本中的中文路径是乱码.今天刚好有时间进行解决下: 首先看看调用代码 "./bin/base-tcl8.6-thread-win32 ...

  7. 浏览器环境下JavaScript脚本加载与执行探析之动态脚本与Ajax脚本注入

    在<浏览器环境下JavaScript脚本加载与执行探析之defer与async特性>中,我们研究了延迟脚本(defer)和异步脚本(async)的执行时机.浏览器支持情况.浏览器bug以及 ...

  8. linux,shell脚本中获取脚本的名字,使用脚本的名字。

    需求描述: 写shell脚本的过程中,有时会需要获取脚本的名字,比如,有的时候,脚本 中会有usage()这种函数,可能就会用到脚本的名字. 实现方法: shell脚本中,通过使用$0就可以获取到脚本 ...

  9. 【Head First Servlets and JSP】笔记21:从有脚本到无脚本

    可以建立多态的bean引用吗 使用type,但没有class scope属性默认为“page” 从有脚本到无脚本 1.快速搭建一个测试环境:输入用户名,返回“Hello, 用户名” index.htm ...

  10. Android常见面试笔试题目

    Android常见面试笔试题目 1.在多线程编程这块,我们经常要使用Handler,Thread和Runnable这三个类,那么他们之间的关系你是否弄清楚了呢? 答:可以处理消息循环的线程,他是一个拥 ...

随机推荐

  1. 使用AnimatorOverrideController动态更换animationclip注意事项

    http://www.ceeger.com/forum/read.php?tid=19138 public AnimationClip clip; Animator anim; void Awake( ...

  2. 17..userinfo.txt 文件中存放以下结构:

    alex:alex3714 wusir:123456 meet:meet123 1.让用户选择: 1.注册 2.登录 2.用户选择注册就将账号和密码添加到userinfo.txt中,如果用户名存在就提 ...

  3. 多线程 GCD队列组

    //  DYFViewController.m //  623-08-队列组 // //  Created by dyf on 14-6-23. //  Copyright (c) 2014年 ___ ...

  4. day02 多态

  5. java数据结构----带权图

    1.带权图:要引入带权图,首先要引入最小生成树,当所有的边拥有相同的权值时.问题变得简单了,算法可以选择任意一条边加入最小生成树.但是当边有不同的权值时,需要用一些算法决策来选择正确的边. 2.带权图 ...

  6. 学习java设计模式的必要性探讨

    1.设计模式是什么:设计模式为我们提供了一套可复用的面向对象技术,再配合重构方法,可以让我们避免简单重复的工作.它使用面向接口编程,而不是面向实现.可以说设计模式是java程序设计的灵魂. 2.为什么 ...

  7. java对mongodb数据库的简单操作

    准备工作: 下载好mongodriver.jar包(https://oss.sonatype.org/content/repositories/releases/org/mongodb/mongodb ...

  8. [題解](縮點)luogu_P2341受歡迎的牛

    對於每個強聯通分量,這些牛一定都互相喜歡,所以縮點(我也不知道怎麼想到的) 接下來就是統計答案,最後縮成了一個DAG圖,如果這個點是明星的話,其他每個點一定直接或間接的鏈接這個點 也就是說其他點一定有 ...

  9. 大数加法 HDU 1002

    #include <iostream> #include <cstring> #include <string> #include <cstdio> # ...

  10. 洛谷1072(gcd的运用)

    已知正整数a0,a1,b0,b1,设某未知正整数x满足: 1. x 和 a0 的最大公约数是 a1​: 2. x 和 b0​ 的最小公倍数是b1. Hankson 的“逆问题”就是求出满足条件的正整数 ...