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 ...
 
随机推荐
- 了解html表单
			
html表单 表单的根标签:form form标签属性 action:处理表单业务的后台代码的位置(URL) method:提交方式 post get 默认值 enctype:encode type ...
 - docker--发布docker镜像
			
前戏 前面我们自己做了个docker镜像,我们可以上传到docker hub,别人就可以下载使用了 发布到docker hub 我们前面使用docker search 查找的镜像都是从docker h ...
 - 【day04】css
			
一.CSS2.0[Cascading Style Sheets]层叠样式表 1.什么是CSS:修饰网页元素(标记)外观(比如给文字加颜色,大小,字体)的,W3C规定尽量用CSS样式替代XHTML属性 ...
 - [LeetCode] 99. Recover Binary Search Tree 复原二叉搜索树
			
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...
 - 本地手动一步步搭建WNMP环境(nginx+php+mysql) Windows平台
			
环境:Windows 10 x64 参考文章: WNMP完整教程 windows下PHP环境的搭建 我自定义安装后的目录结构: +WNMP ++MySQL_Server-8.0.13 ++n ...
 - 【洛谷】P4594 [COCI2011-2012#5] BLOKOVI
			
本来已经有一个专门记录洛谷题目的博客了,但这个题之毒瘤...... 为你专门写一篇总行了吧...... 传送门 先说一句,这个题每次摆放都靠到最右边不一定是最优的 因为它可以这个亚子 就是说上面那个块 ...
 - ping不通服务器的解决方法
			
参考腾讯云的解决办法: https://cloud.tencent.com/document/product/213/14639#CheckOSSetting 我的服务器是aws的, 解决方法大同小异 ...
 - PHP服务端优化全面总结
			
一.优化PHP原则 1.1PHP代码的优化 (1)升级最新的PHP版本 鸟哥PPT里的对比数据,就是WordPress在PHP5.6执行100次会产生70亿次的CPU指令执行数目,而在PHP7中只需要 ...
 - 微信小程序起步
			
微信小程序 文档 微信小程序开发文档 本质 so微信小程序到底是什么?是原生的app还是H5应用? 简单来说,小程序是一种应用,运行的环境是微信(App)进程中,使用了部分的H5技术 目录介绍 app ...
 - nodejs anywhere 搭建本地静态文件服务
			
一.背景 工作中有时候往往会遇到下述场景:例如需要将新打好的安装包等文件临时性的给到同事,可能还需要给到多个同事.这时,我们往往有如下几种方案: 1,一般都会有公司内部的文件系统,上传文件后将对应的地 ...