用數組寫檢測網絡鏈接的腳本

#!/bin/bash
. /etc/init.d/functions

url_list=(
http://192.168.0.201
http://www.baidu.com
http://xxx.elearningch.com
http://www.sina.com
)

wait(){
    echo -n "it will start three seconed later"
    for ((i=0;i<3;i++))
      do
          echo -n "."; sleep 1
      done
 echo
}
#wait

check_url(){
    for ((i=0;i<${#url_list[@]};i++))
      do
          judge=($(curl -I -s --connect-timeout 2 ${url_list[$i]} | head -1|
tr "\r" "\n"))
          if [[ "${judge[1]}" == '200' && "${judge[2]}" == 'OK' ]];then
               action "${url_list[$i]} is success" /bin/true
             else
               action "${url_list[$i]} is failer" /bin/false
          fi
      done
}
check_url


~                  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章