You are on page 1of 2

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 00:00:00. 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 mr.aljhon tronics


1,858 views Aug 5, 2022
Donation is very welcome:
Gcash account: Angel Jhon 09305273559
Paypal account: paypal.me/angeljhon08

You might also like