While语句循环以及监控web服务案例

while

sh xxxx & ##加上&符号,代表在后台执行

[root@server1 test]# sh fuzai.sh &
[1] 10019               ##在后台执行
[root@server1 test]# jobs
[1]+  Running                 sh fuzai.sh & ##查看后台运行程序
[root@server1 test]# fg 1       ##fg加编号调在前台执行
sh fuzai.sh
^C                  ##ctrl+c停止执行并关闭;ctrl+z暂停执行,还在jobs队列之中,bg恢复执行.

实例1:1加到100

#!/bin/bash
i=1
sum=0
while (( i <= 100 ))
do
    let sum=$sum+$i
    ((i++))
done
printf "$sum\n"
[root@server1 test]# seq  10|tac
10
9
8
7
6
5
4
3
2
1
            ##加tac倒叙
#!/bin/bash
i=10
while (( i >= 1 ))
do
    echo $i
    ((i--))
done

监控web服务案例

#!/bin/bash
while true
do
    if [[ ` curl -o /dev/null -s -w "%{http_code}" http://www.baidu.com` -ne 200 ]]     ##检查返回值是否是200
    then 
        echo "this is error!"
    else
        echo "it's right!"
    fi
    sleep 2
done
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值