欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Linux 檢測服務器是否連接著網(wǎng)絡

 更新時間:2017年05月18日 10:14:23   作者:Kxvz  
這篇文章主要介紹了Linux 檢測服務器是否連接著網(wǎng)絡的相關(guān)資料,需要的朋友可以參考下

Linux 檢測服務器是否連接著網(wǎng)絡

摘要: 每隔5分鐘檢測一次服務器是否連接著網(wǎng)絡,如果三次檢測都沒有網(wǎng)絡?則自動關(guān)機! 主要使用場景: 由于自己有一臺服務器放在偏遠的老家,有可能會遇到停電導致斷網(wǎng)的問題,并且停電后UPS使用時間也有限制, 因此設計此腳本為了解決停電的時候服務器突然斷電引起的各種問題,當停電后網(wǎng)絡也就不通了,此時需要自動關(guān)閉服務器. 當然,來電后需要手動啟動服務器!!!

 #!/bin/bash

# 檢測服務器是否連接著網(wǎng)絡,如果網(wǎng)絡不通 則 3次后 關(guān)機
# crontab -e
# */5 * * * * ./check.sh

echo "Starting test network was clear..."

if test -e ./checkInfo
 then
 echo "CheckInfo File Exist..."
else
 cat /dev/null > ./checkInfo
fi

last_res=`head -1 ./checkInfo`

checkInternet(){
 ping_res=1

 for url in "8.8.8.8" "61.139.2.69" "114.114.114.114" "168.95.1.1" "223.5.5.5" "180.76.76.76"
 do
 echo "PING ${url}"

 ping=`ping -c 3 ${url}|awk 'NR==7 {print $4}'`

 if [ ${ping} -eq 0 ]
  then
  ping_res=1
  else
  ping_res=2
 fi

 if [ ${ping_res} -eq 2 ]
  then
  break
 fi
 done

 return ${ping_res}
}

checkInternet

result="$?"

if [ ${result} -eq 1 ]
 then
 if [ "${last_res}" = "1" ]
  then
  echo "2" > ./checkInfo
 elif [ "${last_res}" = "2" ]
  then
  cat /dev/null > ./checkInfo
  init 0
  else
  echo "1" > ./checkInfo
 fi
 else
 cat /dev/null > ./checkInfo
fi

 感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論