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

来源:互联网 发布:哪个软件可以伴奏 编辑:程序博客网 时间:2024/06/02 02:37

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/bashi=1sum=0while (( i <= 100 ))do    let sum=$sum+$i    ((i++))doneprintf "$sum\n"
[root@server1 test]# seq  10|tac10987654321            ##加tac倒叙#!/bin/bashi=10while (( i >= 1 ))do    echo $i    ((i--))done

监控web服务案例

#!/bin/bashwhile truedo    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 2done
原创粉丝点击