Page 1 of 1

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

Posted: Mon Oct 24, 2016 12:37 pm
by voxter
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.

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

Posted: Mon Oct 24, 2016 12:40 pm
by normis
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

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

Posted: Mon Oct 24, 2016 7:31 pm
by voxter
That would only have it run once - I'm trying to ensure that it runs every single time the device boots up.

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

Posted: Tue Oct 25, 2016 12:49 am
by voxter
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!

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

Posted: Fri Oct 28, 2016 9:32 pm
by voxter
*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.

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

Posted: Mon Oct 31, 2016 11:57 am
by mrz
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

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

Posted: Mon Oct 31, 2016 12:20 pm
by normis
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.