0% found this document useful (0 votes)
872 views2 pages

Broundout Problem Solve by Scheduler

The document discusses fixing uptime resets that occur due to sudden power interruptions. It proposes using a scheduler script to save the active user's uptime to Mikrotik's memory by commenting the uptime in the user, scheduler, and script sections. The script backups the active user's uptime every 5 seconds and restores it after reboot by subtracting the active time from the original limit and updating the user profile. This ensures uptime is not lost during an unexpected power outage.

Uploaded by

Erwin Flores
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
872 views2 pages

Broundout Problem Solve by Scheduler

The document discusses fixing uptime resets that occur due to sudden power interruptions. It proposes using a scheduler script to save the active user's uptime to Mikrotik's memory by commenting the uptime in the user, scheduler, and script sections. The script backups the active user's uptime every 5 seconds and restores it after reboot by subtracting the active time from the original limit and updating the user profile. This ensures uptime is not lost during an unexpected power outage.

Uploaded by

Erwin Flores
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Fix Uptime Reset on sudden Power Interruption

August 28, 2022


The issue of uptime problem is when the active user didn't logout or safe mikrotik
shutdown the active user uptime is not save to user statistic uptime.
An example to this is a user with 2hrs limit-uptime and he/she used it for an hour
then an unexpected power interuption happen,
as a result the active uptime used by user is not save and the uptime statistic of
user is still [Link]. There are different ways of fixing uptime reset causes by
power interuption.
Saving active user uptime using a scheduler script to mikrotik memory like comment
in (user, scheduler and script), creating a scheduler, script source or file that
containing there current active uptime.
I choose using comment on scheduler created by user validity.

Note: Currently using JuanFi WiFi Vendo system. For Reference visit JuanFi by Ivan
Alayan

1.) add a script to the end of On-Logout in user profile

User Profile On Logout

/sys sch set [find where name=$user] comment="";

-----------------------------------------------------------------------------------
----------------------

2.) copy and paste to terminal to create scheduler

Mikrotik Terminal

/system scheduler
add interval=5s name="uptime backup" on-event=":local hsactiveuptime;\r\
\n:local hsuser;\r\
\n:local hslimit;\r\
\n\r\
\n:if ([/ip hotspot active print count-only] > 0) do={\r\
\n:foreach i in=[/ip hotspot active find] do={\r\
\n:set hsactiveuptime [/ip hotspot active get \$i uptime];\r\
\n:set hsuser [/ip hotspot active get \$i user];\r\
\n:set hslimit [/ip hotspot user get \$hsuser limit-uptime];\r\
\n/system scheduler set [find where name=\$hsuser] comment=\"temp \$hsacti\
veuptime\";\r\
\n\t\t}\r\
\n\t}\r\
\n" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-time=startup
add name="uptime restore" on-event=":local ucom;\r\
\n:local hsolduptime;\r\
\n:local hsnewuptime;\r\
\n:local hsactiveuptime;\r\
\n:local hsuser;\r\
\n:local temp; \r\
\n:foreach ie in=[/sys sch find] do={\r\
\n :set \$ucom [/sys sch get \$ie comment]; \r\
\n:if (\$ucom != \"\") do={ \r\
\n:set \$temp [:pick \$ucom 0 4];\r\
\n:if (\$temp = \"temp\") do={\r\
\n :set \$hsuser [/sys sch get \$ie name]; \r\
\n:if ([/ip hotspot user find name=\$hsuser]) do={\r\
\n:set \$hsolduptime [/ip hotspot user get [find where name=\$hsuser] limi\
t-uptime];\r\

\n:set \$hsactiveuptime [:pick \$ucom 5 ([:len \$ucom] + 1)]; \r\


\n:set \$hsnewuptime (hsolduptime - \$hsactiveuptime);\r\
\n/ip hotspot user set [find where name=\$hsuser] limit-uptime=\$hsnewupti\
me;\r\

\n/sys sch set [find where name=\$hsuser] comment=\"\";} else={ /sys sch r\
emove \$ie;}\r\
\n}}}" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-time=startup

-----------------------------------------------------------------------------------
-------------------------------------------

As you read the script the uptime backup will get the active users uptime and it
will comment the current active uptime
of user to the user scheduler for every 5 seconds. By adding the OnLogout script it
will remove the user scheduler
comment because it will automatically saved to uptime statistics of user. The issue
on sudden Power Interruption with
fix by uptime restore and it will run after 3 seconds of Mikrotik bootup.

credits to [Link] tronics


1,858 views Aug 5, 2022
Donation is very welcome:
Gcash account: Angel Jhon 09305273559
Paypal account: [Link]/angeljhon08

You might also like