Community discussions

MikroTik App
用户头像
frank333
Member
Member
Topic Author
Posts: 311
加入: Mon Dec 18, 2017 12:17 pm
Location:S.Marino Router model: RB3011UiAS-RM

Writing a script in Scheduler.

Sat Nov 26, 2022 3:24 pm

With ros 7.6 I tried to write a script directly in Scheduler and this works.
I ask is it correct to do this or what problems might it bring?
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11440
加入: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Writing a script in Scheduler.

Sun Nov 27, 2022 4:44 pm

There's no point in making scripts separately and then running them in the scheduler.

Non ha senso fare gli script a parte e poi richiamarli nello scheduler...
Top
用户头像
Jotne
Forum Guru
Forum Guru
Posts: 3219
加入: Sat Dec 24, 2016 11:17 am
Location:Magrathean

Re: Writing a script in Scheduler.

Mon Nov 28, 2022 8:16 am

So you say that if you make a script that needs to be scheduled, just copy/past script in the scheduler and do not use the script function at all?
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11440
加入: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Writing a script in Scheduler.

Mon Nov 28, 2022 12:08 pm

Indeed...

You don't have a drop-down menu where you can choose the script, but an area identical to that of the scripts where you can insert... the script...

In the scheduler if you "call" the script, you just create a script that calls the script...

If you need to call the source of a script to do something else, you can do exactly the same with the scheduler text.

Difference between scheduler and script: none except that the script doesn't start by itself, the scheduler can put a "timer" on it...
Top
用户头像
Jotne
Forum Guru
Forum Guru
Posts: 3219
加入: Sat Dec 24, 2016 11:17 am
Location:Magrathean

Re: Writing a script in Scheduler.

Mon Nov 28, 2022 12:12 pm

Learning new things every day. Thanks:)
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11440
加入: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Writing a script in Scheduler.

Mon Nov 28, 2022 12:18 pm

Thanks:)
Top
用户头像
Amm0
Forum Guru
Forum Guru
Posts: 2291
加入: Sun May 01, 2016 7:12 pm
Location:California

Re: Writing a script in Scheduler.

Tue Dec 06, 2022 9:46 pm

With ros 7.6 I tried to write a script directly in Scheduler and this works.
I ask is it correct to do this or what problems might it bring?
Yeslargelya difference without distinction.

Only two minor differences:
  • 如果你需要一样的script in *multiple* scheduled tasks.... In this case, it be better to have your script in /system/scripts, so there be only one copy of your code to edit or change.
  • Or you want "manually" run your script... e.g. /system/script has "run script" while schedule does not (without changing the schedule).
  • In Schedule, you can just put the name of the script as the "On Event" to invoke another script, while in /system/script you have to use the full command to call another script.
Top
用户头像
frank333
Member
Member
Topic Author
Posts: 311
加入: Mon Dec 18, 2017 12:17 pm
Location:S.Marino Router model: RB3011UiAS-RM

Re: Writing a script in Scheduler.

Tue Dec 06, 2022 10:13 pm

thanks for the info, and since you can't put reactions to every post I'll put them here :lol:
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11440
加入: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: Writing a script in Scheduler.

Tue Dec 06, 2022 11:17 pm

[*] If you need the same script in *multiple* scheduled tasks.... In this case, it be better to have your script in /system/scripts, so there be only one copy of your code to edit or change.
Better to have each script copied multiple times for each scheduler.
If for some reason you modify the script that is called by multiple schedules
and for some reason later turns out to be faulty, not just one, but all of the schedules stop working.
Or modifying the script could cause one or more schedules to no longer behave correctly if the script is modified,
for some unforeseeable reason at the outset.


[*] Or you want "manually" run your script... e.g. /system/script has "run script" while schedule does not (without changing the schedule).

not true:
Code:Select all
[[:parse [/system scheduler get  on-event]]]
Top
用户头像
Amm0
Forum Guru
Forum Guru
Posts: 2291
加入: Sun May 01, 2016 7:12 pm
Location:California

Re: Writing a script in Scheduler.

Tue Dec 06, 2022 11:58 pm

To the OP, as you can see it doesn't matter. This is really just personal preferences.

FWIW something I do neither. Instead of script or schedule, I sometimes just copy a script with functions to the file system, and then use :import it (from CLI, schedule, etc.) to load the all my script functions. This is pretty quick to load a very large script file, and has a verbose=yes and start-after= options so you can debug a large script or ROS functions. So the file system be the third way, all have some differences (as you see here)

I have no idea why there is a strong opinion that ONLY valid way is ALWAYS put code in the schedule itself & never use schedule to call scripts – everything has it's place.
[*] Or you want "manually" run your script... e.g. /system/script has "run script" while schedule does not (without changing the schedule).
not true:
Code:Select all
[[:parse [/system scheduler get  on-event]]]


Yes I know how parse works. I was referring to winbox dialog box for "System Scripts" that has a nice little "Run Script"BUTTON... but schedule does not. At the CLI, youcouldcall :parse with [[[]]] and remember it's actually "on-event" not "script"... But "saved code" in /system/scripts, can be called using "run" (e.g. /system/script/run