Shell 编程 until语句

本篇主要写一些shell脚本until语句的使用。
计算1-50的和
#!/bin/bash
i=0
s=0
until [ $i -eq 51 ];do
let s+=i;let i++
done
echo $s
[root@localhost ~]# vim sum.sh
[root@localhost ~]# chmod +x sum.sh
[root@localhost ~]# ./sum.sh
1275
为指定用户发送在线消息
#!/bin/bash
username=$1
# 判断格式是否正确
if [ $# -lt 1 ] ;then
echo "Usage:`basename $0` <username> [message]"
exit 1
fi
# 判断用户是否存在
if grep "^$username:" /etc/passwd > /dev/null ;then :
else
echo "用户不存在"
exit 1
fi
# 判断用户是否在线,不在则每5s联系一次
until who|grep "$username" > /dev/null ;do
echo "用户不在线"
sleep 5
done
# 发送信息
mes=$*
echo $mes | write $username
[root@localhost ~]# vim message.sh
[root@localhost ~]# chmod +x message.sh
[root@localhost ~]# ./message.sh
Usage:message.sh <username> [message]
[root@localhost ~]# ./message.sh zhangsan hello
用户不存在
[root@localhost ~]# useradd zhangsan && echo "000000" | passwd --stdin zhangsan
Changing password for user zhangsan.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# ./message.sh zhangsan hello
用户不在线
用户不在线
^C
[zhangsan@localhost ~]$
[root@localhost ~]# ./message.sh zhangsan hello
[zhangsan@localhost ~]$
Message from root@localhost on pts/0 at 02:25 ...
zhangsan hello
EOF
Shell 编程 until语句的更多相关文章
- shell编程——if语句【转载】
(2)shell编程——if语句_macg_新浪博客http://blog.sina.com.cn/s/blog_6151984a0100ekl6.html shell编程——if语句转载 if 语句 ...
- 【转载】shell编程——if语句 if -z -n -f -eq -ne -lt
shell编程中条件表达式的使用 if 条件then Commandelse Commandfi 别忘了这个结尾 If语句忘了结尾fites ...
- Shell 编程 循环语句
本篇主要写一些shell脚本循环语句的使用. for 循环 指定次数 #!/bin/bash for ((i=1;i<=10;i++)) do echo $i done [root@localh ...
- Shell 编程 case语句
本篇主要写一些shell脚本case语句的使用. 字符判断 #!/bin/bash read -p "请输入一个字符:" char case $char in [a-z]|[A-Z ...
- Shell 编程 条件语句
本篇主要写一些shell脚本条件语句的使用. 条件测试 test 条件表达式 [ 条件表达式 ] 文件测试 -d:测试是否为目录(Directory). -e:测试文件或目录是否存在(Exist). ...
- shell编程——if语句 if -z -n -f -eq -ne -lt
if 条件then Commandelse Commandfi 别忘了这个结尾 If语句忘了结尾fitest.sh: line 14: sy ...
- shell编程——if语句
if 语句格式 if 条件 then Command else Command fi 别忘了这个结尾 If语句忘了结尾fi test.s ...
- Linux Shell编程case语句
http://blog.csdn.net/dreamtdp/article/details/8048720 case语句适用于需要进行多重分支的应用情况. case分支语句的格式如下: case $变 ...
- 1.Shell编程循环语句(if 、while、 until)
循环语句 for循环语句 读取不同的变量值,用来逐个执行同一组命令 格式: for 变量名 in 取值列表 do 命令序列 done 示例:批量创建用户并设置密码 [root@localhost da ...
随机推荐
- Basics of Algorithmic Trading: Concepts and Examples
https://www.investopedia.com/articles/active-trading/101014/basics-algorithmic-trading-concepts-and- ...
- testcontainers 方便的db测试框架
testcontainers是一个强大,简单,基于容器的db测试解决方案 目前已经支持了主流的开发语言 参考资料 https://github.com/testcontainers/testconta ...
- CSS3中的px,em,rem,vh,vw
1.px:像素,精确显示 2.em:继承父类字体的大小,相当于“倍”,如:浏览器默认字体大小为16px=1em,始终按照div继承来的字体大小显示,进场用于移动端 em换算工具:http://www. ...
- 7.18 NOIP模拟测试5 星际旅行+砍树+超级树
T1 星际旅行 题意:n个点,m条边,无重边,有自环,要求经过m-2条边两次,2条边一次,问共有多少种本质不同的方案.本质不同:当且仅当至少存在一条边经过次数不同. 题解:考试的时候理解错题,以为他是 ...
- mysql 字段修改汇总
-- 增加 ALTER TABLE `gdm_nursing_patient` ADD COLUMN `due_date` date DEFAULT NULL COMMENT '名称' AFTER ...
- golang中判断两个slice是否相等
在golang中我们可以轻松地通过==来判断两个数组(array)是否相等,但遗憾的是slice并没有相关的运算符,当需要判断两个slice是否相等时我们只能另寻捷径了. slice相等的定义 我们选 ...
- Angular中上传图片到分布式文件服务器FastDFS上
使用步骤 1.上传下载需要的依赖 2.springmvc中配置多媒体解析器并加载 <!-- 配置多媒体解析器 --> <bean id="multipartResolver ...
- [转帖]k8s 如何让你的应用活的更久
k8s 如何让你的应用活的更久 https://www.jianshu.com/p/132319e795ae 众所周知,k8s 可以托管你的服务 / 应用,当出现各种原因导致你的应用挂掉之后,k8s ...
- ext.net 这两个id不是同一个对象,小心!
今天遇到了一个很奇怪的问题,查到最后发现是下面代码原因 代码中使用store存储js对象 mcp_liststore.data.items[3].id mcp_liststore.data.get(3 ...
- spring boot 在eclipse里启动正常,但打包后启动不起来
现象描述: spring boot 在eclipse里启动正常,但打包后启动不起来. 错误日志如下: D:\Project>java -jar MKKY_CMS.jar . ____ _ __ ...