Community discussions

MikroTik App
 
Alex920807
just joined
Topic Author
Posts: 2
Joined: Tue Jan 05, 2021 12:14 am

Stop command for scripts

Fri Jun 18, 2021 9:29 pm

Hey all.


So I have a script that reboots a router after 5 minutes.

Then I set a net watch to keep pining an ip and if no response is detected to start the reboot script.

If the ip reply’s within the 5 minutes before the reboot script is executed. What is the command used to stop the script

Eg

\system script run reboot (in down of net watch)
\system script stop reboot (in up of netwatch)

Stop is not working for me. I dont think it’s the right phrase.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Stop command for scripts

Fri Jun 18, 2021 9:33 pm

Reboot act instantly, you can not stop reboot process.

What you ask is to stop the script, is possible must be complicated.

Use another easy method:

After 5 min "reboot" check one :global variable, if the global variable, set as "yes" on start of reboot script before the delay,
is changed to "no" from another script or command, do not reboot.
Last edited by rextended on Sun Jun 20, 2021 1:39 am, edited 1 time in total.
 
nescafe2002
Forum Veteran
Forum Veteran
Posts: 897
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: Stop command for scripts

Fri Jun 18, 2021 9:46 pm

Better use the watchdog feature

https://wiki.mikrotik.com/wiki/Manual:System/Watchdog

watch-address
The system will reboot, in case 6 sequential pings to the given IP address will fail. If set to none this feature is disabled. By default router will reboot every 6 minutes if watch-address is set and not reachable.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Stop command for scripts

Sat Jun 19, 2021 9:23 pm

This is NOT what OP require.
Watchdog reboot instantly after 6 consecutive ping, on 6 seconds.
The user want stop reboot process if the line go back on 5 minues after fail.
 
nescafe2002
Forum Veteran
Forum Veteran
Posts: 897
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: Stop command for scripts

Sat Jun 19, 2021 10:47 pm

Imo the XY problem is applicable here - OP already has created a reboot script which he wants to interrupt so he asks for a scripting solution; the watchdog module doesn't require scripting at all.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Stop command for scripts

Sun Jun 20, 2021 1:28 am

if you have nothing useful to add or not willing to help at all, please try to refrain from replying.

Since you don't understand, I'll give you a summary.

>>>He have a script that reboots a router after 5 minutes the script are launched.
>>>He set a netwatch to keep ping one IP and if no response is detected, start the reboot script.
>>>If the IP reply within the 5 minutes before the script is executed, the script must be halted

He ask for a solution to stop the script, not for reboot instantly or after 6 seconds.

Understand or not?
 
nescafe2002
Forum Veteran
Forum Veteran
Posts: 897
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: Stop command for scripts

Sun Jun 20, 2021 1:38 am

In a fair and sensible way, OP is free to take my advice or not.

But are you, rextended, accusing me of forum pollution? Really? Lol..
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Stop command for scripts

Sun Jun 20, 2021 1:40 am

if you have nothing useful to add or not willing to help at all, please try to refrain from replying.
It's your own sentence, don't you recognize it? You do not respect it, you who wrote it?
posting.php?mode=quote&f=2&p=863038
 
nescafe2002
Forum Veteran
Forum Veteran
Posts: 897
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: Stop command for scripts

Sun Jun 20, 2021 1:51 am

Ok, ontopic, let me further explain my thoughts here.

OP has created a 5-min reboot script which is triggered by a netwatch entry.
This makes sense because netwatch fires directly after startup - restarting directly would create a boot loop.
When there is a connection - OP wants to cancel the reboot script for which you provided helpful hints to achieve.

Now, let's look at the bigger picture. What is the problem? Netwatch creates a boot loop. That's why the 5-minute wait is introduced in the first place.
If OP uses watchdog instead of netwatch, no script is required, no 5-minute delay is necessary and there is no need for a "stop command".
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Stop command for scripts

Sun Jun 20, 2021 2:07 am

( @nescafe2002 sorry for the link etc. :( I shouldn't do that )

Watching even bigger picture,
If the problem with remote host happen after 8h and 27min, for example?
It want reboot the device BUT want delay 5 min on hope the connection return back.

P.S.: But the OP will come back again or is another one-post-and-go-away-forever?
 
nescafe2002
Forum Veteran
Forum Veteran
Posts: 897
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: Stop command for scripts

Sun Jun 20, 2021 2:15 am

I'm assuming the 5 minute timeout is introduced by OP solely to prevent a boot loop, but if it's necessary to add a waiting period for all outages, you can alter the watchdog ping-timeout parameter.

ping-timeout (time; Default: 60s) - Specifies the time interval in which the device will be pinged 6 times (after "no-ping-delay");
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Stop command for scripts

Sun Jun 20, 2021 2:17 am

(I hope you fully read my previous post)

set this to (5min * 60sec) 300 seconds ping 6 times (300/6 = one each 50 sec)?
/system watchdog
set ping-start-after-boot=5m ping-timeout=5m watch-address=192.168.1.1 watchdog-timer=yes

Who is online

Users browsing this forum: No registered users and 21 guests