Community discussions

MikroTik App
 
atillaeyice
just joined
Topic Author
Posts: 8
Joined: Mon Oct 31, 2016 8:57 pm

Script fails to connect Trying to loop it

Wed Apr 18, 2018 4:45 pm

Hello Im in need of some help have setup script to update devices firmware settings etc .. all at same time. but than my web server that i run on my private network can not handle all the devices connecting at same time. which 04.00 Am so what im attempting to do after this update if success device reboots so i wanted to call in a scheduler to check if devices rebooted if not so which means connection timed out so i wanted to repeat here is the script i have the only problem is if this one fails to it has to be check until gets sysuptime < 1 hrs

{
:local Stime [/system resource get uptime]
:while ($Stime > 01:00:00) do={
:log warning "Update Failed Retrying!"; :interface bridge set 0 name=null; :interface bridge set 1 name=null1; :log warning "BridgeID & FwID Reset OK!"; :tool fetch url=http://0.0.0.0/autoupdate.rsc port=3131 password=**** user=****; :import autoupdate.rsc;
}
}

so basically i want if that fails keeps trying every 5 mins until gets that autoupdate.rsc file executed and system gets rebooted. due autoupdate.rsc script.
 
2frogs
Forum Veteran
Forum Veteran
Posts: 713
Joined: Fri Dec 03, 2010 1:38 am

Re: Script fails to connect Trying to loop it

Wed Apr 18, 2018 7:17 pm

Use a Global Variable instead of uptime. In your initial script add;
:global AutoUpdateStatus

and just before your fetch command add
:$AutoUpdateStatus=“on”

Now 5 min should be;
:global AutoUpdateStatus
:local AutoUpdateTimer

:if $AutoUpdateStatus=“on” do {:if $AutoUpdateTimer!=“on” do {:$AutoUpdateTimer=“on”}
else={:$AutoUpdateTimer=“off”; :log warning "Update Failed Retrying!"; :interface bridge set 0 name=null; :interface bridge set 1 name=null1; :log warning "BridgeID & FwID Reset OK!"; :tool fetch url=http://0.0.0.0/autoupdate.rsc port=3131 password=**** user=****; :import autoupdate.rsc;}}
 
atillaeyice
just joined
Topic Author
Posts: 8
Joined: Mon Oct 31, 2016 8:57 pm

Re: Script fails to connect Trying to loop it

Thu Apr 19, 2018 10:50 am

Use a Global Variable instead of uptime. In your initial script add;
:global AutoUpdateStatus

and just before your fetch command add
:$AutoUpdateStatus=“on”

Now 5 min should be;
:global AutoUpdateStatus
:local AutoUpdateTimer

:if $AutoUpdateStatus=“on” do {:if $AutoUpdateTimer!=“on” do {:$AutoUpdateTimer=“on”}
else={:$AutoUpdateTimer=“off”; :log warning "Update Failed Retrying!"; :interface bridge set 0 name=null; :interface bridge set 1 name=null1; :log warning "BridgeID & FwID Reset OK!"; :tool fetch url=http://0.0.0.0/autoupdate.rsc port=3131 password=**** user=****; :import autoupdate.rsc;}}
thank you for your answer but i did not get the logic how does it knows that every 5 mins what i want to do here from 04.00 Am to 05.00 Pm check every 5 minutes where did you state the time on this script
 
2frogs
Forum Veteran
Forum Veteran
Posts: 713
Joined: Fri Dec 03, 2010 1:38 am

Re: Script fails to connect Trying to loop it

Thu Apr 19, 2018 3:21 pm

Put it in scheduler with interval 00:05:00. It will run every 5 minutes. It actually makes the next attempt to update every 5-10 minutes depending on when your original script actually processes and this one runs. This script will attempt to update until it is done. On reboot, the variables are cleared, so next time it checks $AutoUpateStatus in will not equal "on" so the script will just quit. I did not see a requirement for it to only run between 4:00 and 5:00, as your script also ran until it completed. The only mention of 4:00 was your Update Script.
 
atillaeyice
just joined
Topic Author
Posts: 8
Joined: Mon Oct 31, 2016 8:57 pm

Re: Script fails to connect Trying to loop it

Thu Apr 19, 2018 4:11 pm

Put it in scheduler with interval 00:05:00. It will run every 5 minutes. It actually makes the next attempt to update every 5-10 minutes depending on when your original script actually processes and this one runs. This script will attempt to update until it is done. On reboot, the variables are cleared, so next time it checks $AutoUpateStatus in will not equal "on" so the script will just quit. I did not see a requirement for it to only run between 4:00 and 5:00, as your script also ran until it completed. The only mention of 4:00 was your Update Script.
Thanks Got it now

Who is online

Users browsing this forum: No registered users and 8 guests