Community discussions

MikroTik App
 
gutekpl
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 92
Joined: Wed Feb 20, 2019 6:31 pm

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

Mon May 13, 2019 10:24 am

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?
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1782
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

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

Mon May 13, 2019 10:36 pm

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).
 
gutekpl
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 92
Joined: Wed Feb 20, 2019 6:31 pm

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

Wed May 15, 2019 1:18 pm

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?
 
NetWorker
Frequent Visitor
Frequent Visitor
Posts: 98
Joined: Sun Jan 31, 2010 6:55 pm

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

Wed May 15, 2019 5:22 pm

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
 
gutekpl
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 92
Joined: Wed Feb 20, 2019 6:31 pm

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

Wed May 15, 2019 6:26 pm

Works, Thank You once more.
 
NetWorker
Frequent Visitor
Frequent Visitor
Posts: 98
Joined: Sun Jan 31, 2010 6:55 pm

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

Wed May 15, 2019 10:49 pm

Awesome! Glad I could help. :D

Who is online

Users browsing this forum: Kentzo and 22 guests