shelll脚本,常见的脚本题目。
[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脚本,常见的脚本题目。的更多相关文章
- 脚本AI与脚本引擎
Scripted AI and Scripting Engines 脚本AI与脚本引擎 This chapter discusses some of the techniques you can us ...
- iOS面试中常见的算法题目
一.前言 这里是在iOS求职中自己遇到的算法题,希望对大家有所帮助.不定期更新.如果大家想在线运行代码调试,可以将代码拷贝到这里.然后进行调试.下面就是常见的算法题目. 二.正文 1.就n的阶乘.(这 ...
- centos shell编程6一些工作中实践脚本 nagios监控脚本 自定义zabbix脚本 mysql备份脚本 zabbix错误日志 直接送给bc做计算 gzip innobackupex/Xtrabackup 第四十节课
centos shell编程6一些工作中实践脚本 nagios监控脚本 自定义zabbix脚本 mysql备份脚本 zabbix错误日志 直接送给bc做计算 gzip innobacku ...
- unity中js脚本与c#脚本互相调用
unity中js脚本与c#脚本互相调用 test1.js function OnGUI() { if(GUI.Button(Rect(25,25,100,30),"JS Call CS& ...
- JavaScript值延迟脚本和异步脚本
Html 4.0为<script>标签定义了defer属性,这个属性的用途是表名脚本在执行时,不会影响页面的构造.也就是说,脚本会延迟到整个页面解析完毕之后在运行,因此,在<scri ...
- tcl脚本直接执行脚本中中文识别不了的处理
上一篇说tcl中文乱码是因为我写了个bat调用该脚本,但是脚本中的中文路径是乱码.今天刚好有时间进行解决下: 首先看看调用代码 "./bin/base-tcl8.6-thread-win32 ...
- 浏览器环境下JavaScript脚本加载与执行探析之动态脚本与Ajax脚本注入
在<浏览器环境下JavaScript脚本加载与执行探析之defer与async特性>中,我们研究了延迟脚本(defer)和异步脚本(async)的执行时机.浏览器支持情况.浏览器bug以及 ...
- linux,shell脚本中获取脚本的名字,使用脚本的名字。
需求描述: 写shell脚本的过程中,有时会需要获取脚本的名字,比如,有的时候,脚本 中会有usage()这种函数,可能就会用到脚本的名字. 实现方法: shell脚本中,通过使用$0就可以获取到脚本 ...
- 【Head First Servlets and JSP】笔记21:从有脚本到无脚本
可以建立多态的bean引用吗 使用type,但没有class scope属性默认为“page” 从有脚本到无脚本 1.快速搭建一个测试环境:输入用户名,返回“Hello, 用户名” index.htm ...
- Android常见面试笔试题目
Android常见面试笔试题目 1.在多线程编程这块,我们经常要使用Handler,Thread和Runnable这三个类,那么他们之间的关系你是否弄清楚了呢? 答:可以处理消息循环的线程,他是一个拥 ...
随机推荐
- C++函数调用过程深入分析
http://blog.csdn.net/dongtingzhizi/article/details/6680050 0. 引言 函数调用的过程实际上也就是一个中断的过程,那么C++中到底是怎样实现一 ...
- $.ajax()与vue结合获取数据并渲染
html: <div id="app1"> <ul> <li v-for="item in datas"> <div ...
- 113 Path Sum II 路径总和 II
给定一个二叉树和一个和,找到所有从根到叶路径总和等于给定总和的路径.例如,给定下面的二叉树和 sum = 22, 5 / \ 4 ...
- echarts 百度地图 json
百度ECharts地图Json数据在线下载 最近需要写一个echarts地图统计表,苦于弄不到对应的地图json文件, CSDN 上下载的很多不完整或者不能用,功夫不负苦心人找到了这个. 阿里云地图选 ...
- Jquery多选框互相内容交换
<head runat="server"> <title>无标题页</title> <script type="text/jav ...
- SQL Server 查看列,添加列,修改列,删除列
查看表:exec sp_help 表名 查看列: exec sp_columns 表名 查看列:select * from information_schema.columns where table ...
- Yii2 之 UrlManager 实践 (一)
1. enablePrettyUrl yii2默认不支持类似 http://<domain>/site/error 的url格式,需要在config.php中启用 enablePrett ...
- drupal6提示 Compilation failed: disallowed Unicode code point (>= 0xd800 && <= 0xdfff) at offset 9 on line 615
解决办法:将sites\all\modules\ctools\includes\cleanstring.inc文件中的61行改成62行这样子即可,如下图
- Android 两个ArrayList找出相同元素及单个ArrayList删除元素
//从一个ArrayList中删除重复元素 List<String> arrayList1 = new ArrayList<String>(); arrayList1.add( ...
- 严重:The web application [web01] appears to have started a thread named ...
Tomcat报错 严重:The web application [web01] appears to have started a thread named [PooledThread-1] but ...