i believe that to “run script x-times after every boot” and “enabling scheduler after boot, running script x time, then disabling scheduler till next reboot” is from “ChangeBand” script point of view same - this script will be started x-times. If you want to talk about resource usage, of course there are differences: my scheduler runs all time, so there is CPU usage, but not single FLASH write. Disabling/enabling scheduler will save some CPU cycles, but generate FLASH writes. You have to decide what is better. I think i can write set of script enabling/disabling scheduler too.
One question: How does the script “A” with code
:if ($counter <= 5) do={/system script run ChangeBand} else={:set counter ($counter-1)}
>
> work?
> The way I read it translates into: "If counter is less than 5 run the "ChangeBand" script, and if not (so bigger or equal 5) then ?????"
>
> I don't understand what the code
>
> > {:set counter (\$counter-1)}
>
> is doing? What it should do is to stop the scheduler to run this script, or to stop this script itself all by itself...
I am so sorry for this, i was meant as joke. Assuming counter is signed 32bit integer, and you run scheduler every 20seconds, it will take 497,102 days (1,361 years) to overflow,:set counter ($counter-1) takes care of that - you can safely delete that part, script will still work.
> And by the way, where are all these "\r\" and "\n" coming from? They weren't there in my original script. What do they do?
are they in your script in winbox when you open script for editing? No, they only appear when you do export, **/system script export**, that's the way MT exports scripts
> I think actually now it is impossible to stop a scheduler from running without disabling it.
> MT should make that option in it as mentioned before.
>
> The reason is that I am tidy and don't like it when a script runs eternally while it has no more function...., but it only has to start again at the next reboot.
You first post had not mentioned that. You wanted to run some script x-times after every boot. And that is what my script is exactly doing, copy and paste this in winbox terminal window (and you might need to press enter to submit last line):
```text
/system script
add name=A policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=\
"log info \"Script A start\"\r\
\n:global counter\r\
\n:set counter (\$counter+1)\r\
\n:if (\$counter <= 5) do={/system script run B}\r\
\n:log info \"Script A end\""
add name=B policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=\
":global counter\r\
\n:log info (\"Script B run number:\".\$counter)"
add name=simulatereboot policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=\
":global counter 0"
/system scheduler
add disabled=no interval=3s name=schedule2 on-event=A policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-date=jun/17/2011 \
start-time=13:15:16
simulatereboot script will reset counter, so you don’t have to reboot. And you can watch messages in winbox Log window.
That is my last attempt to prove that this script is working. If you want me to write scheduler enable/disable stuff, let’s talk outside forum.
BTW messing with wifi config every boot doesn’t seems too tidy to me.