I’m a newbie at scripting, so I need some help to get this running.
I’m working with MikroTik OS 7.9 (stable), and I’ve seen many problems with LTE interfaces. I can’t find a solution (we can’t upgrade the OS version because my client doesn’t want to). Usually, the error I see is “SIM is not detected,” and I have to log in via LAN and reboot the router, or send someone to do it manually.
The idea of the patch is to use a script on the router that pings Google’s DNS, and if it fails, it will trigger a reboot.
However, it doesn’t work. Even when I launch the script from the CLI using /system script run PingCheckReboot, the reboot prompt still needs to be confirmed.
I saw that I can’t use without-prompt=yes on my OS version, so I really don’t know how to fix it.
I would be very grateful if someone could help me!
Have a nice day
FIrst thing, a forced reboot is not a very good idea (you lose log), and it should be used as last-last solution if everything else fails.
So you should try if the connection resumes after performing some “softer” actions (enable/disable the LTE interface or the USB bus, or something else depending on which device is it).
This said, if you really-really want to force a reboot, you can use (reported to be working on7.8, so likely it will work on 7.9):
Until you test the script on the terminal, you have everytime to confirm y/n.
Only :execute “/sys reboot” can avoid that on terminal (and is :execute “/sys reboot” not :execute {/sys reboot}).
If you run the script on scheduler, confirmation are not needed.
I’ve been thinking about it, and I’m going to try this, using
:execute
instead of
:do
as u told.:
/system script add name=PingCheckReboot policy=reboot,test,read,write source=":local failedCount 0; :local totalCount 20; :local threshold 10; :for i from=1 to=\$totalCount do={ :if ([:len [/ping 8.8.8.8 count=1 interval=300ms]] = 0) do={ :set failedCount (\$failedCount + 1) } }; :log info (\"PingCheck: Fallos de ping: \$failedCount de \$totalCount\"); :if (\$failedCount > \$threshold) do={ :log warning \"PingCheck: Umbral superado. Reiniciando router...\" :execute /system reboot} else={ :log info \"PingCheck: Dentro del umbral, sin reinicio.\" }"
I know rebooting should always be the last resort, but resetting the LTE interface doesn’t solve the issue, and the client still doesn’t want to let me upgrade the OS, so…
I’ll reply tomorrow to let you know if it works. Thanks a lot!
If 8.8.8.8 do not respond for 6 times on 60 seconds, the device reboot (1 ping each 10 seconds is the default)
but you can change the interval to 6s, so it ping 8.8.8.8 each second for 6 seconds, so if do not reply, the unit reboot.
Although what @jaclaz wrote is correct. Maybe trying a USB/PCIe reset first is faster and less shocking for the RouterBOARD.