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这三个类,那么他们之间的关系你是否弄清楚了呢? 答:可以处理消息循环的线程,他是一个拥 ...
随机推荐
- [Xcode 实际操作]九、实用进阶-(16)给图片添加水印效果
目录:[Swift]Xcode实际操作 本文将演示如何截取屏幕画面,并将截取图片,存入系统相册. 在项目文件夹[DemoApp]上点击鼠标右键 ->[New File]创建一个扩展文件-> ...
- PJzhang:robots协议的实际场景
猫宁!!! 参考链接: https://bbs.360.cn/thread-15062960-1-1.html https://ziyuan.baidu.com/college/courseinfo? ...
- Centos5.11 使用yum源
由于我是用的系统是Centos 5.11以停止更新很多年,故此yum也不能用,找了很多方法,最终yum能稳定的运行在Centos5.11上,下面开始一一讲解步骤: 1:首先更新yum源 地址:http ...
- MySQL 索引及优化实战
https://blog.csdn.net/qq_21987433/article/details/79753551 https://tech.meituan.com/mysql_index.html ...
- PHP面向对象static关键字
1.静态属性用于保存类的公有数据 2.静态方法里面只能访问静态属性 3.静态成员不需要实例化就可以访问 4.类的内部可以通过self或者static关键字访问自身的静态成员 5.可以通过parent关 ...
- 502的错误其实不是nginx的问题,要从后端找原因。php-cgi进程数不够用、php执行时间长、或者是php-cgi进程死掉,都会出现502错误。
502的错误其实不是nginx的问题,要从后端找原因.php-cgi进程数不够用.php执行时间长.或者是php-cgi进程死掉,都会出现502错误.
- ArrayList简单学习
类声明: public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomA ...
- 542 01 Matrix 01 矩阵
给定一个由 0 和 1 组成的矩阵,找出每个元素到最近的 0 的距离.两个相邻元素间的距离为 1 .示例 1:输入:0 0 00 1 00 0 0输出:0 0 00 1 00 0 0 示例 2:输入: ...
- ASP.NET Core MVC/WebAPi 模型绑定
public class Person { public string Name { get; set; } public string Address { get; set; } public in ...
- #52. 【UR #4】元旦激光炮 (交互式题)
链接:http://uoj.ac/problem/52 刚刚越过绝境长城,只见天空中出现了炫目的光芒 —— 圣诞老人出现了. 元旦三侠立刻进入战斗.生蛋侠.圆蛋侠和零蛋侠分别有 na,nb,ncna, ...