码迷,mamicode.com
首页 > 系统相关 > 详细

shell编程--while循环

时间:2018-04-20 10:54:31      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:while   shell   循环   

脚本

[root@lynn-04 shell]# vim while2.sh

#!/bin/bash
i=6
while [ $i -gt 0 ]
do
    i=$[$i-1]
    echo $i
done

执行结果

[root@lynn-04 shell]# sh while2.sh
5
4
3
2
1
0

脚本

[root@lynn-04 shell]# vim while1.sh

#!/bin/bash
load=`w|head -1|awk -F ‘load average: ‘ ‘{print $2}‘|cut -d. -f1`
while [ $load -lt 10 ]
do
    echo $load
    /usr/lib/zabbix/alertscripts/mail.py 15******68@163.com "load high" "$load"
    exit
done

执行结果 这里是发邮件的脚本 当然我的邮箱也会收到报警邮件

[root@lynn-04 shell]# sh while1.sh
0

shell编程--while循环

标签:while   shell   循环   

原文地址:http://blog.51cto.com/10963213/2105657

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!