訓練家的佈弱格-Patch1.2

The BLOG of trainer



編輯日期:2012-01-25 02:21

類型:網誌
作者:羽山
文章時間:2012-01-25 02:21:22
瀏覽人數:4066人
標題: 斷線又自動重連 -Part II G
網址:http://demo.3wa.tw/blog/blog.php?id=1361
內容:
 

之前寫的 ping 感覺好像有點不太可靠…

遇到群健 dhcp 掛掉,ping 回應的內容好像不如預期,所以我放棄了 shell script 的寫法

改用較熟悉的 php 重寫這部分~

不過我把對象改成 google ... 就個人觀察很久了,google 的 title 從來沒換過,所以應該沒問題 XD

這次改成 network restart 跟 reboot 皆可用~

# crontab -e 如下

#  每 5 分鐘檢查一次連線狀況,不過就重設網路
*/5 * * * * php /root/check_online.php reconnect
#  每 30 分鐘檢查一次連線狀況,不過就重開機
*/30 * * * * php /root/check_online.php reboot

[root@3wa ~]# cat check_online.php
<?php
  @ini_set(\'user_agent\',\'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\');

  $value=@file_get_contents(\"http://www.google.com\");
  @preg_match(\'/<title>(.*)<\\/title>/msi\',$value,$match);
  if(strtoupper($match[1])!=\'GOOGLE\')
  {
    echo \"\\nReconnecting...\\n\";
    if(!is_file(\"/root/reconnect.log\"))
    {
      @touch(\"/root/reconnect.log\");
    }
    switch($_SERVER[\'argv\'][1])
    {
      case \'reconnect\':
        file_put_contents(\"/root/reconnect.log\",
            sprintf(\"%s[%s]Reconnect!\\n\",
                file_get_contents(\"/root/reconnect.log\"),
                date(\'Y-m-d H:i:s\')
            ));
        `/bin/systemctl restart network.service`;
        break;
      case \'reboot\':
      default:
        file_put_contents(\"/root/reconnect.log\",
            sprintf(\"%s[%s]Reboot!\\n\",
                file_get_contents(\"/root/reconnect.log\"),
                date(\'Y-m-d H:i:s\')
            ));
        `/sbin/reboot`;
        break;

    }
  }
?>
[root@3wa ~]#

 

觀察了一陣子log...

.....

[2011-12-17 07:30:57]Reconnect!
[2011-12-17 11:50:57]Reconnect!
[2011-12-17 17:50:58]Reconnect!
[2011-12-17 22:30:58]Reconnect!
[2011-12-18 02:01:38]Reconnect!
[2011-12-18 02:06:52]Reconnect!
[2011-12-18 02:07:08]Reboot!
[2011-12-18 06:26:00]Reconnect!
[2011-12-20 23:00:09]Reboot!
[2011-12-20 23:10:07]Reboot!
[2011-12-21 03:30:57]Reboot!
[2011-12-21 07:55:57]Reconnect!
[2011-12-22 17:15:57]Reconnect!
[2011-12-22 21:05:58]Reconnect!
[2011-12-23 14:40:57]Reboot!
[2011-12-23 18:10:57]Reconnect!
[2011-12-23 22:30:58]Reboot!
[2011-12-24 02:55:57]Reconnect!
[2011-12-28 21:10:58]Reconnect!
[2012-01-01 18:15:58]Reconnect!
[2012-01-02 00:15:57]Reconnect!
[2012-01-14 07:30:58]Reboot!
[2012-01-14 11:40:57]Reconnect!
[2012-01-15 07:10:59]Reconnect!
[2012-01-21 07:45:58]Reconnect!
[root@3wa ~]#


其實還是覺得有點怒,這種三不五十給你偷斷線的感覺很不優...

還好  restart network 還滿可靠的...~\"~

之後就把 reboot 那行 mark 起來了

 

首頁  上十頁  上一頁  1 下一頁    最末頁 (總共有...1頁)

第 1 頁

有話要說  看留言 【0】
其他分類
當月訓練
(2012-01-25)
【網誌】斷線又自動重連 -Part II G

(2012-01-25)
【Linux 心得】microcode 一點心得

(2012-01-25)
【Linux 心得】ATOM 330 Lost Cores...

(2012-01-13)
【程式設計】vim 的註解開關機 F11

(2012-01-01)
【網頁設計心得】寫了一支不錯用的 dbdumper

最新訓練
(2024-09-15)
【FZR 150】FZR維修-大閔廢鐵號

(2024-09-11)
【遊戲 / 生活】更換新的濾水器水龍頭

(2024-09-04)
【NSR 150】NSR150 大燈燈炮更換

(2024-09-01)
【KTM 390】KTM Duke 390 安裝空濾盒、水箱水、油箱、試發動

(2024-08-31)
【KTM 390】KTM Duke 390 引擎上車、節流閥安裝、空濾盒修補、單向閥思考

(2024-08-30)
【機車綜合相關】買了一組盜版牧田DTW1002

(2024-08-25)
【KTM 390】KTM Duke 390 汽門間隙檢查、凸輪軸安裝、汽缸蓋、機油壓力開關

(2024-08-24)
【KTM 390】KTM Duke 390更換內鏈排骨

(2024-08-17)
【KTM 390】KTM Duke 390內鏈排骨問題查修-清洗篇

(2024-08-10)
【KTM 390】KTM Duke 390內鏈排骨問題查修-中(落引擎)