Page 1 of 1

Set timer or some other way to prevent script from running multiple times in short time

Posted: Mon May 13, 2019 10:24 am
by gutekpl
I want to monitor my download to check how often I reach max bandwidth and basing on that decide whether to increase speed at my ISP or not.
I created simple traffic monitor, set trigger to above 100M and pasted this script:
global telegramMessage "100mbps reached!"
/system script run SendToTelegram
Now to prevent spamming over and over what I want to achieve is something like this:
if (bandwidth_already_informed_flag == 0) {
global telegramMessage "100mbps reached!"
/system script run SendToTelegram
set bandwidth_already_informed_flag to 1 for 60 minutes
}
Any ideas?

Re: Set timer or some other way to prevent script from running multiple times in short time

Posted: Mon May 13, 2019 10:36 pm
by sebastia
maybe?
* set a ":global bandwidth_already_informed_flag=1;
* start scheduler to reset in 60min

Another solution: use graphing to monitor usage over longer time interval (not just instantaneous).

Re: Set timer or some other way to prevent script from running multiple times in short time

Posted: Wed May 15, 2019 1:18 pm
by gutekpl
In scripts I created dwnFlagCleaner
:global downloadFlag
set downloadFlag "0"

And in traffic monitor I now have this maxDown
if ($downloadFlag != "1") do={
global telegramMessage "Download 100mbps reached!"
/system script run SendToTelegram
set downloadFlag "1"
--run scheudler here--
}
Now I need to create scheduler which will be started at the end of maxDown and after 60 minutes will execute dwnFlagCleaner. How to do that?

Re: Set timer or some other way to prevent script from running multiple times in short time  [SOLVED]

Posted: Wed May 15, 2019 5:22 pm
by NetWorker
There are two ways to go about doing that. One, you put the scheduled task and enable/disable it as needed. The other, you create and remove it each time.

This is the task you need.
/system scheduler add name=dwnFlagCleaner start-time=startup interval=60m on-event=dwnFlagCleaner
Either add it and disable it or add the line to your script. If you choose the first option you then add this to the script:
/system scheduler enable dwnFlagCleaner
Then you can put an if into the script and either:
/system scheduler disable dwnFlagCleaner
or
/system scheduler remove dwnFlagCleaner

Re: Set timer or some other way to prevent script from running multiple times in short time

Posted: Wed May 15, 2019 6:26 pm
by gutekpl
Works, Thank You once more.

Re: Set timer or some other way to prevent script from running multiple times in short time

Posted: Wed May 15, 2019 10:49 pm
by NetWorker
Awesome! Glad I could help. :D