N
N
Nikolay2019-05-14 18:00:55
Mikrotik
Nikolay, 2019-05-14 18:00:55

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"
}
#####

Tell me how to do it so that:
The presence of the lte port was checked. If it is not there, then reboot. If it is, the CPU load was checked. If the overload then reboot if everything is ok, then the Internet was checked. If everything is ok, then it was displayed ok. If there are problems with the Internet, then reboot USB
Now the script does everything simply one by one and sometimes overlaps each other.
Also, if you have any suggestions, please suggest. I will only be glad.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aborigen1020, 2019-05-16
@Aborigin1020

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 question

Ask a Question

731 491 924 answers to any question