Community discussions

MikroTik App
 
jpil
just joined
Topic Author
Posts: 8
Joined: Wed Feb 15, 2017 2:48 am

Scheduling a script whose content is in the scripts/ directory

Wed Feb 15, 2017 5:36 am

Hi,

I've uploaded some simple scripts to the scripts directory on an rb951g. They show up in Winbox under Files in scripts/. The .rsc files do not show up under /system scripts.

I don't understand how to schedule the .rsc files or perhaps register them as scripts. For example if I have a script called scripts/foo.rsc how can I set the scheduler to run that file?

I am able to use /import to run the script fine. I suppose I could schedule a task with source={import scripts/foo.rsc} but that seems wrong.

Thanks.

-jp
 
User avatar
cdiedrich
Forum Veteran
Forum Veteran
Posts: 997
Joined: Thu Feb 13, 2014 2:03 pm
Location: Basel, Switzerland // Bremen, Germany
Contact:

Re: Scheduling a script whose content is in the scripts/ directory

Wed Feb 15, 2017 11:40 am

Once you imported the script, it's in your script repository. No need to import it again.
Schedule this command
/sys script run foo
-Chris
 
User avatar
karlisi
Member
Member
Posts: 440
Joined: Mon May 31, 2004 8:09 am
Location: Latvia

Re: Scheduling a script whose content is in the scripts/ directory

Wed Feb 15, 2017 4:28 pm

AFAIK .rsc scripts are for configuration tasks only. If you need run script on regular basis, make new script under /system scripts, then schedule it with /system schedule as Chris wrote. More about scripting in RouterOS see in Wiki
http://wiki.mikrotik.com/wiki/Manual:Scripting
http://wiki.mikrotik.com/wiki/Manual:Scripting-examples
 
jpil
just joined
Topic Author
Posts: 8
Joined: Wed Feb 15, 2017 2:48 am

Re: Scheduling a script whose content is in the scripts/ directory

Thu Feb 16, 2017 4:40 am

Thanks for the replies Chris and Karlis.

When I /import a .rsc the text in that file just runs the commands. I don't end up with a new script that I can run rather the text of the rsc is executed. So in the below example I have some code that disables a virtual SSID. When I /import the SSID is taken down. That's it.

I was able to do this:
/system script add name=disable source=[/file get scripts/ssid_disable.rsc contents]
That loads the content of scripts/ssid_disable.rsc into a script that I can see when I do:
/system script print brief

Flags: I - invalid
 #   NAME                             OWNER                             LAST-STARTED          RUN-COUNT
 0   disable                         admin                                                           0
 
And as Chris suggested I now can run this script or even schedule it:
/system script run disable
/system scheduler add interval=1d name=disable on-event=ssid-disable policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=feb/14/2017 start-time=19:00:00
I still feel like I'm missing something since I need to upload the script and then load the text of that file rather than somehow being able to run the script file as it exists.

-jp
 
User avatar
cdiedrich
Forum Veteran
Forum Veteran
Posts: 997
Joined: Thu Feb 13, 2014 2:03 pm
Location: Basel, Switzerland // Bremen, Germany
Contact:

Re: Scheduling a script whose content is in the scripts/ directory

Thu Feb 16, 2017 10:12 am

OK, let's get this sorted.
rsc files are not meant to be run as scripts in the way you describe. Their purpose is to transfer configuration (portions).
So once you imported that script into your scripts repository, you're done. The file can be deleted.

I'm a bit confused about your last code quote:
/system script run disable
/system scheduler add interval=1d name=disable on-event=ssid-disable policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=feb/14/2017 start-time=19:00:00
Here you have two different names - and your script repository only shows one.

The correct scheduler call would rather be
/system scheduler add interval=1d name=disable on-event="/sys script run disable" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=feb/14/2017 start-time=19:00:00
-Chris
 
jpil
just joined
Topic Author
Posts: 8
Joined: Wed Feb 15, 2017 2:48 am

Re: Scheduling a script whose content is in the scripts/ directory

Sat Feb 18, 2017 5:26 pm

Chris,

Yes, there was an error in what I put together re naming.

If I view rsc files as a transfer mechanism things make sense.

Thanks for your help.

jp


Sent from my iPhone using Tapatalk

Who is online

Users browsing this forum: jaclaz, miker3000 and 105 guests