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这三个类,那么他们之间的关系你是否弄清楚了呢? 答:可以处理消息循环的线程,他是一个拥 ...
随机推荐
- lightoj1066【BFS】
题意: 就是按照A->B->C->D....去拿,求步数: 思路: 有一个注意点:如果碰到合法字母吃掉,再以后的某次可以重新到改点: BFS的因为标记而减少了重复位置的到达,但是按照 ...
- hdoj5875【二分+RMQ】
全部从我大哥那里学习得来.. 一开始硬着头皮就是根据思路上线段树,明知是T还要写(因为线段树还不是很熟,趁机练一发) 后来果然T了,然后就去学了一发RMQ的ST算法,查询是O(1). ST算法主要: ...
- std::thread 在DLLMain 中会发生死锁 std::thread cause deadlock in DLLMain
注意不要再DLLMain中使用 std::thread 否则会发生死锁. 但是可以使用 _beginthreadex (此函数可以使用lambda) 或者直接使用windows的底层函数: Creat ...
- 51nod1093(推公式&找規律)
題目鏈接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1093 題意:中文題誒- 思路:xjb 一開始死活想不出怎麼將一 ...
- MyBatist庖丁解牛(三)
从MyBatis代码实现的角度来看,MyBatis的主要的核心部件有以下几个: SqlSession:作为MyBatis工作的主要顶层API,表示和数据库交互的会话,完成必要数据库增删改查功能: Ex ...
- 如何解决netty发送消息截断问题
在netty开发过程中我遇到过长的消息被分割成多个小消息的问题.如下图所示: 其实这两条消息应该是一条消息,它们两个才是一个完整的json字符串.查看代码原来是客户端与服务器端都没有考虑TCP粘包 ...
- GYM 101889E(dp)
dp[i][j][k]表示第i位填数字k时,与后面的相连模数为j时,后面的数字最小填多少. 测得我提心吊胆还以为复杂度高了,结果出来46ms还是cf评测姬强啊. #pragma comment(lin ...
- hdu6313( 2018 Multi-University Training Contest 2)
bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6313 参考dls的讲解: 以5*5的矩阵为例: 后一列分别对前一列+0+1+2+3+4操 ...
- Codeforces Round #497 (Div. 2) C. Reorder the Array
Bryce1010模板 http://codeforces.com/contest/1008/problems #include <bits/stdc++.h> using namespa ...
- linux下php以fastcgi模式运行
关于PHP以fastcgi方式运行的文章,网络上较多,也许由于转载的原因,有些地方不甚明了,笔者亲自测试,整理成文,供大家参考. 1.linux系统 [root@localhost /]# cat / ...