Answer the question
In order to leave comments, you need to log in
Mikrotik: How to set the order of tasks in a script?
Collected a small script.
:local mailAddrTo "[email protected]";
:local cpuLoadSec 5;
#####
if ([/interface find name~"lte"] = "") do={
:log warning "Wait 120 sec to Mikrotik boot";
/system reboot;
:delay 120;
/tool e-mail send to=$mailAddrTo subject="$[/system identity get name]. LTE interface not found. Mikrotik rebooted!" body="LTE interface not found. Mikrotik rebooted!\nTime and Date: $[/system clock get time] $[/system clock get date]"
}
#####
#####
:local cpu100 0;
for x1 from=1 to=$cpuLoadSec do={
:if ([/system resource get cpu-load] = "100") do={
:set cpu100 ($cpu100+1);
}
:delay 1;
}
:if ($cpu100 = $cpuLoadSec) do={
:log warning "Wait 120 sec to Mikrotik boot";
:delay 120;
/tool e-mail send to=$mailAddrTo subject="$[/system identity get name]. CPU load on Mikrotik: 100%." body="Within $cpuLoadSec seconds, CPU load on Mikrotik: 100%. Mikrotik rebooted!\nTime and Date: $[/system clock get time] $[/system clock get date]"
/system reboot;
}
#####
#####
:local PingCount 3
:local Google 8.8.8.8
:local Yandex 77.88.8.7
:local Mail 94.100.180.201
:local ResultGoogle [/ping count=$PingCount $Google]
:local ResultYandex [/ping count=$PingCount $Yandex]
:local ResultMail [/ping count=$PingCount $Mail]
:local MainIfInetOk false;
:set MainIfInetOk (($ResultGoogle + $ResultYandex + $ResultMail) >= (2 * $PingCount))
:put "MainIfInetOk=$MainIfInetOk"
if (!$MainIfInetOk) do={
/log error "Bad connect internet"
/system routerboard usb power-reset duration=5s;
:log warning "Wait 30 sec to modem boot";
:delay 30;
/tool e-mail send to=$mailAddrTo subject="$[/system identity get name]. USB power-reset." body="USB power-reset.\nTime and Date: $[/system clock get time] $[/system clock get date]"
}
if ($MainIfInetOk) do={
/log info "Connect OK"
}
#####
Answer the question
In order to leave comments, you need to log in
Didn't read the code.
There are scripts for checking the lte interface on the Internet, it seems that even on the off-forum there was a topic with discussions and inventions ...
Offhand - use timeouts between command execution.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question