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

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?

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).

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?

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

Works, Thank You once more.

Awesome! Glad I could help. :smiley: