{"id":246,"date":"2014-08-22T16:36:41","date_gmt":"2014-08-22T20:36:41","guid":{"rendered":"http:\/\/www.mufljuz.com\/?p=246"},"modified":"2014-09-23T10:44:53","modified_gmt":"2014-09-23T14:44:53","slug":"net-watchdog-for-openwrt","status":"publish","type":"post","link":"https:\/\/www.mufljuz.com\/?p=246","title":{"rendered":"Net watchdog for OpenWrt"},"content":{"rendered":"<p>Lately, my cable connection gets disconnected too often. To automate reconnection, I installed a simple watchdog script that pings outside address and if there is no response it restarts router network. It&#8217;s not most efficient, since only WAN needs to be restarted, but it does the job. <\/p>\n<p>Here is a simple watchdog script.<\/p>\n<pre>\r\n#!\/bin\/sh\r\nn=0\r\nwhile [ $n -lt 10 ]\r\ndo\r\n  if \/bin\/ping -c 1 8.8.8.8 >\/dev\/null\r\n  then\r\n    exit 0\r\n  fi\r\n  n=$((n+1))\r\ndone\r\n\/etc\/init.d\/network restart\r\n<\/pre>\n<p>First, ssh to router and create this script<\/p>\n<pre>\r\nssh root@192.168.2.1\r\nnano \/root\/watchdog.sh\r\nchmod +x \/root\/watchdog.sh\r\n<\/pre>\n<p>Save it to <code>\/root\/watchdog.sh<\/code>, and give executable permissions<br \/>\n<code>chmod +x \/root\/watchdog.sh<\/code><br \/>\nAdd it to cron in order to execute it every minute:<\/p>\n<pre>\r\n* * * * * \/root\/watchdog.sh\r\n<\/pre>\n<p>You can either add this line using luci web interface at<br \/>\n<a href=\"http:\/\/192.168.1.1\/cgi-bin\/luci\/admin\/system\/crontab\/\" title=\"http:\/\/192.168.1.1\/cgi-bin\/luci\/admin\/system\/crontab\/\">http:\/\/192.168.1.1\/cgi-bin\/luci\/admin\/system\/crontab\/<\/a><br \/>\nor just edit <code>\/etc\/crontabs\/root<\/code> file.<\/p>\n<p>Make sure cron is enabled!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lately, my cable connection gets disconnected too often. To automate reconnection, I installed a simple watchdog script that pings outside address and if there is no response it restarts router network. It&#8217;s not most efficient, since only WAN needs to be restarted, but it does the job. Here is a simple watchdog script. #!\/bin\/sh n=0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/posts\/246"}],"collection":[{"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=246"}],"version-history":[{"count":8,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/posts\/246\/revisions"}],"predecessor-version":[{"id":254,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/posts\/246\/revisions\/254"}],"wp:attachment":[{"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}