Advertisement
n19605gh

Untitled

Feb 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. cd /usr/local/bin/
  2. #!/bin/sh
  3. checkNet_01=`ping -c 2 168.95.1.1 | grep 0% | awk '{print $6}'`
  4. checkNet_02=`ping -c 2 61.31.1.1 | grep 0% | awk '{print $6}'`
  5.  
  6. # echo 訊息為 debug 用,取消註解即可顯示
  7. echo $checkNet_01
  8. echo $checkNet_02
  9.  
  10. # 檢查變數是否「not」0%,若條件成立,則代表網路不正常
  11. # 若網路不正常,則呼叫「其它處理腳本或指令」
  12. # 為避免誤判,只有在兩家 ISP DNS 都 ping 不到的情況下,條件才成立
  13.  
  14. 跑sh沒有出現0%
  15. 出現
  16. received,
  17. received,
  18.  
  19. 後來我用
  20. #!/bin/bash
  21. sites='http://www.google.com/ http://tw.yahoo.com/'
  22.  
  23. for site in $sites ; do
  24. wget -t 2 -T 120 $site -O- >/dev/null 2>&1
  25. if [ $? != 0 ] ; then
  26. reboot
  27. else
  28. echo "Connection OK"
  29. fi
  30. done
  31. 就成功了
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement