Script Error

Hi, we have a simple script that checks for internet connectivity via the LTE interface but i seem to have an error when it runs when the LTE interface isn’t working.

I’m not sure if its something simple like i have the interface name wrong, would someone mind taking a look and provide some feedback please.

Script

:if ([/ping 8.8.8.8 count=10] = 0) do={
:log error "** LTE DOWN **";
/interface disable lte
/delay 5s	
/interface enable lte
} else={
:log info "** LTE ONLINE **";
}

List of interfaces

Flags: D - dynamic, X - disabled, R - running, S - slave 
 #     NAME                                TYPE       ACTUAL-MTU L2MTU  MAX-L2MTU
 0  R  ether1                              ether            1500  1596       2026
 1     ether2                              ether            1500  1596       2026
 2     ether3                              ether            1500  1596       2026
 3  R  lte1                                lte              1480

Many Thanks

You try to disable/enable interface lte, but name of your interface is lte1

Thank you@jotne

I did wonder if that was the case but when i jump into the termninal and type

/interface lte1

i get an error, where as if i type

/interface lte

it works?

Is it something to do with Name V’s Type ?

Thanks

Is not a “type”, is a submenu / section, like on /interface wireless you find the dedicated section for… wireless
/interface show all type of interfaces, usually the menu is less rich than the dedicated section for each type of interfaces.

This script work on both way: disable and enable command are present on both generic /interface and dedicated /interface lte section.
But the interface name is lte1

Revised script:

/interface lte
:if ([:ping 8.8.8.8 count=10] = 0) do={
    :log warning "** LTE DOWN **"
     disable lte1
     :delay 5s
     enable lte1
} else={
    :log info "** LTE ONLINE **"
}

Thanks @rextended

Turns out the problem we had was due to a previous reboot and the LTE interface didn’t load for some reason.

I was thinking of adding something like this to the script

:if ([/interface list print count-only where name=LTE] = 0) do={
:log error "** LTE INTERFACE OFFLINE **";
/system reboot
}

but would need an additional else statement. Is that possible or am i better off have a dedicated alternative script scheduled to run first.

Thanks


Thanks

Missing lte interface cause previous script to fail… give me 10 minutes…

this is wrong:
/interface list print count-only where name=LTE

at least
/interface print count-only where type=“lte” (or /interface print count-only where name=“lte1”)
or
/interface lte print count-only where name=“lte1” (or simply /interface lte print count-only)

but really must be do on this way:
[:len [/interface lte find]]

because the print command, with some exception, is related mostly to put text on terminal than manage variables.

Remember on /system logging to save the warning/error logs on DISK file, or you lost that info on reboot (you can not send e-mail or sms if lte1 not work)

ltestatus added for warn only one time when status change

:global ltestatus
:if ([:typeof $ltestatus] = "nothing") do={:set ltestatus "offline"}
/interface lte
:if ([:len [find]] > 0) do={
    :if ([:ping 8.8.8.8 count=10] = 0) do={
        :if ($ltestatus = "online") do={:log warning "*** LTE NOT WORK ***"}
        :set ltestatus "offline"
         disable [find]
         :delay 5s
         enable [find]
    } else={
        :if ($ltestatus = "offline") do={:log info "*** LTE ONLINE ***"}
        :set ltestatus "online"
    }
} else={
   :log error "*** LTE DISAPPEARED ***"
   /system reboot
}

You can put it on scheduler directly without creat separate script,
set the scheduler to start the action on “startup” and run every 4 minutes and 30 seconds (because is already present 30s delay inside script),
and add this before any line of script,
for give the time to the system to finish booting:

:delay 30s

WOW… thank you @rextended, thats very helpfull of you.

I will get this loaded onto a RB this morning and test everything, it will be a great, robust script to check the LTE interface and keep it online hopefully.

Grazie mille

Di niente :laughing:

@rextended

Sorry to resurrect this thread, i wanted to ask a question if i may.

Is there a way to alter this script so if the ping response fails three times it will reboot the router rather than disable / enable the LTE interface.

I have seen the below issue a couple of times and i believe the LTE interface is crashing due to a number of “not registered” errors but i am not sure if that means the LTE interface doesn’t exist which the script does check for. The above example happened following an automated router reboot which happens everyday at 23:00

RB.png
Thanks

I would rather reboot the “modem” instead of the router, that way you still keep the logs, etc

below amended script from @rextended:

:global ltestatus
:if ([:typeof $ltestatus] = "nothing") do={:set ltestatus "offline"}
/interface lte
:if ([:len [find]] > 0) do={
    :if ([:ping 8.8.8.8 count=10] = 0) do={
        :if ($ltestatus = "online") do={:log warning "*** LTE NOT WORK ***"}
        :set ltestatus "offline"
         # disable [find]
         # :delay 5s
         # enable [find]
         /system routerboard usb power-reset duration=10
    } else={
        :if ($ltestatus = "offline") do={:log info "*** LTE ONLINE ***"}
        :set ltestatus "online"
    }
} else={
   :log error "*** LTE DISAPPEARED ***"
   /system reboot
}

Yes…

:global ltestatus
:if ([:typeof $ltestatus] = "nothing") do={:set ltestatus "offline"}
/interface lte
:if ([:len [find]] > 0) do={
    :if ([:ping 8.8.8.8 count=10] < 8) do={
        :log error "*** LTE NOT WORK CORRECTLY - REBOOT ***"
        /system reboot
    } else={
        :if ($ltestatus = "offline") do={:log info "*** LTE ONLINE ***"}
        :set ltestatus "online"
    }
} else={
   :log error "*** LTE DISAPPEARED ***"
   /system reboot
}

Once again @rextended, thank you very much. I presume the “< 8” command is the count ?

@CZFan, thanks for the help, all critical logs are written to disk so the router reboot is teh bets option for me.

at least 3 fail?
10 - 3 = 7 (at least 7 good)
< 8 (worst than 8, because 8 are good, only 2 fail)

Arh, Ok that makes more sense. Thanks for all your help on this

@pigsfoot, I think what you looking for is:

[:ping 8.8.8.8 count=3] = 0

This will send 3 ping requests, if all 3 fails, then do what is required…

If not, you will have to elaborate on your requirement

Too much strict, someting can fill the connection and reboot the device without reason…

Agree, but it is what he asked.

I would like to use this script, would you mind changing it to monitor 2 devices on innerweb, i.e. ping both 8.8.8.8 and 1.1.1.1 and if both fails, then take action?

Nevermind, think I have it working…

:global ltestatus
:if ([:typeof $ltestatus] = "nothing") do={:set ltestatus "offline"}
/interface lte
:if ([:len [find]] > 0) do={
    :if (([:ping 8.8.8.8 count=5] = 0) && ([ping 1.1.1.1 count=5] = 0)) do={
            :log warning "*** LTE Connection Down, Reboot Modem... ***"
            /system routerboard usb power-reset duration=10
    } else={
        :if ($ltestatus = "offline") do={:log info "*** LTE ONLINE ***"}
        :set ltestatus "online"
    }
} else={
   :log error "*** No LTE Interfaces... ***"
   /system reboot
}

Just some suggestions

We abandoned central dns addresses like 8.8.8.8 for all of our customer LTE-links because we sometimes encountered global routing errors while the local link still worked. We now only use addresses within ISP’s own networks to probe for possible link errors. There is also a delay of one minute before resetting the LTE-link since it showed that many link errors are automatically restored within that time period.

Normally we don’t reboot the device as just flipping the interface works equally well.

We also send error message regarding link failure etc via SMS and together with external monitoring on the LTE-device we can correlate any downtime to investigate whether the problem originates from the operator network or the local installation.

As a last resort when there are no available ip-connections we can check status or reboot the device by acting on incoming SMS commands. This has proven to be very useful and saved many hours of unnecessary travel as many LTE links are installed in remote branch offices far out in the countryside and on some remote islands.