Community discussions

MikroTik App
 
voxter
just joined
Topic Author
Posts: 5
Joined: Mon Oct 24, 2016 12:32 pm

Fetch succeeds, dies, then deletes file when called from Scheduler??

Mon Oct 24, 2016 12:37 pm

Hi there,

I'm pulling my hair out over here, hoping you guys can offer some guidance. I'm trying to create a script that, on boot up, will reach out to a remote server, download a "config file" of sorts (or any set of commands) and execute them. In order to achieve this, I'm using a fetch, then calling /import on the file. When I run this script via the CLI, it works perfectly. When I let it execute from the scheduler (on boot), it gets as far as the fetch, the file shows up in the filesystem for a brief second, then vanishes and the script stops there.

What might I be doing wrong here? Is this a bug?

The script:
/system script add name="OnBoot-ConfigFetch" source={/tool fetch url="https://cpe.mydomain.com/routeros/mikrotik-onboot.rsc" mode="https" dst-path="mikrotik-onboot.rsc";/import mikrotik-onboot.rsc;}
/system scheduler add disabled=no name=OnBoot-ConfigFetch on-event=OnBoot-ConfigFetch start-time=startup interval=0s
Running the script with /system script run OnBoot-ConfigFetch works flawlessly. The script _does_ get called successfully via the scheduler, but stops executing after the fetch command.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26912
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia
Contact:

Re: Fetch succeeds, dies, then deletes file when called from Scheduler??

Mon Oct 24, 2016 12:40 pm

You could simplify it by calling your file "name.auto.rsc", in this case it will auto execute:
http://wiki.mikrotik.com/wiki/Manual:Co ... tic_Import
 
voxter
just joined
Topic Author
Posts: 5
Joined: Mon Oct 24, 2016 12:32 pm

Re: Fetch succeeds, dies, then deletes file when called from Scheduler??

Mon Oct 24, 2016 7:31 pm

That would only have it run once - I'm trying to ensure that it runs every single time the device boots up.
 
voxter
just joined
Topic Author
Posts: 5
Joined: Mon Oct 24, 2016 12:32 pm

Re: Fetch succeeds, dies, then deletes file when called from Scheduler??

Tue Oct 25, 2016 12:49 am

Also, I am incredibly interested to understand why the behavior of the script / fetch is so negatively affected when run by the scheduler versus being run by hand. That is the bigger concern for me for sure!
 
voxter
just joined
Topic Author
Posts: 5
Joined: Mon Oct 24, 2016 12:32 pm

Re: Fetch succeeds, dies, then deletes file when called from Scheduler??

Fri Oct 28, 2016 9:32 pm

*bump*

I appreciate that the forums are public, and responses may vary.

If nobody is able to comment on this, is there a way for me to pay for support to get an answer?

Or, perhaps someone can suggest another way to achieve what I'm trying to accomplish:
- We plug in a brand new mikrotik, and either via netinstall or by simply putting a script.auto.rsc file on there, it kicks off a process to call home to us, ask for a config file, download it and apply it
- On subsequent reboots, or forced script execution, also call home and see if there are any changes (and if so, download + execute)

The first part is totally achievable right now, but because fetch is seemingly dying when used on a scheduler set for "startup", I cant find a way to have a re-check-in happen after a reboot.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7188
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Fetch succeeds, dies, then deletes file when called from Scheduler??

Mon Oct 31, 2016 11:57 am

Probably script stops on fetch command because fetch returns some kind of an error.
You can catch that error and proceed with script execution, see example here
http://wiki.mikrotik.com/wiki/Manual:Sc ... ime_errors
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26912
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia
Contact:

Re: Fetch succeeds, dies, then deletes file when called from Scheduler??

Mon Oct 31, 2016 12:20 pm

That would only have it run once - I'm trying to ensure that it runs every single time the device boots up.
Yes, but your script can then be simplified. All you need to do is schedule a single fetch. The scrip will be auto-executed and file will be deleted, until next boot.

Who is online

Users browsing this forum: No registered users and 3 guests