Community discussions

MikroTik App
 
gotsprings
Forum Guru
Forum Guru
Topic Author
Posts: 2335
Joined: Mon May 14, 2012 9:30 pm

Schedule vs Script Question

Tue Jun 26, 2018 11:55 pm

I read the manual about scheduler and it states that if multiple schedules have "startup" as their setting... they run in order listed in schedule.

"Rebooting the router will reset run-count counter.

If more than one script has to be executed simultaneously, they are executed in the order they appear in the scheduler configuration. This can be important if one scheduled script is used to disable another one."

Looking at my log...
17:59:07 system,info router rebooted
17:59:07 system,info,critical cpu not running at default frequency
17:59:08 script,info Fire2 Starting
17:59:08 script,info Fire1 Starting up and delaying.

Its not even doing the things in order like its supposed to and they both fired at the same time.
 
msatter
Forum Guru
Forum Guru
Posts: 2945
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Schedule vs Script Question

Wed Jun 27, 2018 2:32 am

That page is not up-to-date.

Set the Start Time for the first to 00:00:01 and the second to 00:00:02.
 
gotsprings
Forum Guru
Forum Guru
Topic Author
Posts: 2335
Joined: Mon May 14, 2012 9:30 pm

Re: Schedule vs Script Question

Wed Jun 27, 2018 11:27 pm

:delay 00:04:45

At the beginning of the script.

Sheduler is set for 5 minutes.
 
msatter
Forum Guru
Forum Guru
Posts: 2945
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Schedule vs Script Question

Thu Jun 28, 2018 9:32 am

:delay 00:04:45 At the beginning of the script.
Sheduler is set for 5 minutes.
You don't have to use delay and you can use the scheduler itself:
Knipsel.JPG
This will start every time when it is 34 minutes over an hour and every two hours.

Schedule 1 (script 1): start time 00:00:05 interval 00:05:00
Schedule 2 (script 2): start time 00:00:10 interval 00:05:00

The scheduled scripts will be run every 5 minutes and there will be a 5 second difference in start time between them.
You do not have the required permissions to view the files attached to this post.
 
gotsprings
Forum Guru
Forum Guru
Topic Author
Posts: 2335
Joined: Mon May 14, 2012 9:30 pm

Re: Schedule vs Script Question

Thu Jun 28, 2018 2:19 pm

Well i guess lets talk about what the script does.

Every 5 minutes is sends 5 pings to the default ISP's DNS server. If it misses more than 3 pings... it issues a command to a web power switch to shut down the modem.

That script shuts off its scheduler and turns on another one that has 30 minute interval. Which flips the Outlet back on. Waits 4 minutes. Then sends the pings.

So problem one...
If the script runs at boot up... the modem likely is not fully booted. So its going to fail. Thats going to shut down the modem and roll to the secondary ISP. In 30 minutes the Modem will be brought back up... and the system will flip.

But what I would really want to do is...
Script 1 runs at start up.
First thing it does is disable both scripts that check the ISP.

Then it fetches the time
:local timetest [/system clock get time]
:log info $timetest
Then I would like to add 5 minutes to the time.
Taking a guess here
:local scriptstart (:put $timetest+00:05:00)
Then Update the scripts start times
/system schedule [find comment~"Pinger"] start-time=$scriptstart
Last edited by gotsprings on Thu Jun 28, 2018 3:23 pm, edited 2 times in total.
 
berzins
just joined
Posts: 10
Joined: Thu Apr 05, 2018 2:46 pm

Re: Schedule vs Script Question

Thu Jun 28, 2018 2:44 pm

Wouldn't a simple " :delay 5m; " at the very start of the script do the job then? The scheduler will start the script itself, but no code will be executed for the first 5 minutes.
 
gotsprings
Forum Guru
Forum Guru
Topic Author
Posts: 2335
Joined: Mon May 14, 2012 9:30 pm

Re: Schedule vs Script Question

Thu Jun 28, 2018 2:51 pm

Think I got it...
:global Time [/system clock get time]
:delay 00:00:02
:global SetTime (:put $Time+00:05:00)
/system schedule set start-time=$SetTime [find name~"Pinger"]
 
gotsprings
Forum Guru
Forum Guru
Topic Author
Posts: 2335
Joined: Mon May 14, 2012 9:30 pm

Re: Schedule vs Script Question

Thu Jun 28, 2018 3:26 pm

Wouldn't a simple " :delay 5m; " at the very start of the script do the job then? The scheduler will start the script itself, but no code will be executed for the first 5 minutes.
I did try that...
:delay 00:04:45

At the beginning of the script.

Sheduler is set for 5 minutes.
Just trying to make it more specific.