shell编程--while循环

脚本

[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******[email protected] "load high" "$load"
    exit
done

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

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

猜你喜欢

转载自blog.51cto.com/10963213/2105657