/system scheduler add interval=10m name=ping_watchdog on-event=":global ITERATION 0;\r\ \n:global IP1 8.8.8.8;\r\ \n:global IP2 8.8.4.4;\r\ \n:log debug \"watchdog: start\";\r\ \n:while (true) do={\r\ \n :if ([:len [/system resource usb find]] < 2) do={\r\ \n :log error \"watchdog: could not find modem card - reboot\";\r\ \n :log debug \"watchdog: end\";\r\ \n :delay 5;\r\ \n /system reboot;\r\ \n :delay 1;\r\ \n }\r\ \n :if ([/port get number=0 channel] > 5) do={\r\ \n :log error \"watchdog: large number of channels on port - reboot\"\ ;\r\ \n :log debug \"watchdog: end\";\r\ \n :delay 5;\r\ \n /system reboot;\r\ \n :delay 1;\r\ \n }\r\ \n :if ([/port find inactive=no] != \"\") do={\r\ \n :global PING1 [/ping \$IP1 count=10];\r\ \n :if (\$PING1 > 5) do={\r\ \n :log info \"watchdog: ping1 - ok\";\r\ \n :log debug \"watchdog: end\";\r\ \n :quit\r\ \n }\r\ \n :global PING2 [/ping \$IP2 count=10];\r\ \n :if (\$PING2 > 5) do={\r\ \n :log info \"watchdog: ping2 - ok.\";\r\ \n :log debug \"watchdog: end\";\r\ \n :quit\r\ \n }\r\ \n :if (\$ITERATION < 3) do={\r\ \n :log warning \"watchdog: could not ping - reconnect\";\r\ \n /interface ppp-client enable ppp-out1;\r\ \n :log debug \"watchdog: switching interface - ppp-out1\";\r\ \n :set \$ITERATION (\$ITERATION+1);\r\ \n :delay 60\r\ \n :log debug \"watchdog: next step\";\r\ \n } else={\r\ \n :log error \"watchdog: could not ping - reboot\";\r\ \n :log debug \"watchdog: end\";\r\ \n /system routerboard usb power-reset duration=3;\r\ \n :delay 5;\r\ \n /system reboot;\r\ \n :delay 1\r\ \n }\r\ \n } else={\r\ \n :log error \"watchdog: could not find port - reboot\";\r\ \n :log debug \"watchdog: end\";\r\ \n :delay 5;\r\ \n /system reboot;\r\ \n :delay 1\r\ \n }\r\ \n}" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive \ start-time=startup :delay 0