rest all counters hotspot

I have Microtik routerOS v4.5. I want to rest all counter of my hotspot first of each month automatically.(what is the correct interval since length of months are not equal)

Is it correct to add the fallowing two scripts and one schedule?

:local date
 :local day
 :local month
 :local year
 :local yeardiv
 :local yearmult
 :local leapyear
 :local lastday
 :global found 
  
 :set date [system clock get date]
 :set month [:pick $date 0 3]
 :set day [:pick $date 4 6]
 :set year [:pick $date 7 11]
 
 :set yeardiv ($year / 4)
 :set yearmult ($yeardiv * 4)
 
 :if ([$yearmult] = $year) do={ :set leapyear true } else={ :set leapyear false }
 :if ([$month] = "jan") do={ :set lastday 31 }
 :if ([$month] = "feb") do={ 
        :if ($leapyear = true) do={ :set lastday 29 }
        :if ($leapyear = false) do={ :set lastday 28 } }
 :if ([$month] = "mar") do={ :set lastday 31 } 
 :if ([$month] = "apr") do={ :set lastday 30 }
 :if ([$month] = "may") do={ :set lastday 31 }
 :if ([$month] = "jun") do={ :set lastday 30 }
 :if ([$month] = "jul") do={ :set lastday 31 }
 :if ([$month] = "aug") do={ :set lastday 31 }
 :if ([$month] = "sep") do={ :set lastday 30 }
 :if ([$month] = "oct") do={ :set lastday 31 }
 :if ([$month] = "nov") do={ :set lastday 30 }
 :if ([$month] = "dec") do={ :set lastday 31 }
 :if ([$lastday] = $day) do={ :set found true } else={ :set found false }



:global found
 
 /system script run monthend
 
 :if ([$found] = true) do={  /ip hotspot user reset-counters}



 /system scheduler add name=oversight on-event=oversight start-time=23:50:00 interval=24h

That would work. You could also use the below, which is shorter and doesn’t rely on globals. It assumes that it’ll be fine to reset counters at 1 second past midnight on the 1st, which makes the date math much simpler (“is the day right now equal to ‘01’”):

:local date [/system clock get date]; 
:local dayYear [:pick $date ([:find $date "/" 0] + 1) [:len $date]]; 
:local day [:pick $dayYear 0 [:find $dayYear "/" 0]]; 
:if ($day = "01") do={
   [...whatever...]
}

Then schedule to run at 00:00:01 of whenever, with an interval of 24 hours.

this is faster, thank you fewi

inside “do”, is it enough to have each command in separate line. What is the correct form?

:local date [/system clock get date];
:local dayYear [:pick $date ([:find $date "/" 0] + 1) [:len $date]];
:local day [:pick $dayYear 0 [:find $dayYear "/" 0]];
:if ($day = "01") do={  
/system script run remove_active
/ip hotspot user reset-counters
}

Yes, that should work. I like ending each line in a semicolon, but it’s not strictly necessary.

what kind of programming language is this one?

Is there manual for this language so you can create the script you want?

Yes, it’s in the RouterOS manual: http://wiki.mikrotik.com/wiki/Manual:Scripting

I run hotspot with users and manually add transferlimit when adding users of 500mb.

At this stage I manually reset counters on the first day of each month. I will however make use of this script.

My other problem: As users use all of their 500mb, they purchase another 500mb. What would be the easiest way to make this work and have it all reset on the 1st of the month in other words, They loose whatever is left of the extra data purchased and restart a new 500mb.

All help appreciated!