Greetings friends, I have the following script
:local time 6m
:local atime [ /system clock get time ]
:local adate [ /system clock get date ]
:local comment "$user conect: $adate at: $atime"
:local thours ($atime + $time)
:if ([ /ip hotspot user get $user comment ]="") do={ [ /ip hotspot user set $user comment=$comment ] }
[/system scheduler add name=$user on-event="/ip hotspot user remove \"$user\" \r\
\n/ip hotspot cookie remove [find user=\"$user\"] \r\
\n/system scheduler remove [find name=\"$user\"] \r\
\n\r\
" start-date=$adate start-time=$thours]
the problem is that when there is a electric cut of several hours, the script does not delete the user, because the date has already passed, I don’t know if you understand me. Thanks for your help.
EL DONCITO.
I see that you have constant problems with dates.
For me, you are really wrong in approaching things…
And again, if the user register @2022/07/16 23:54:00 and you give it 6min,
is never disconnected because the scheduler on your script is scheduled @2022/07/16 00:00:00… in the past…
You just don’t want to understand that anything you do that adds time to the system time is always a wrong thing???
Instead of creating a scheduled event for each user,
use a recursive scheduled event that checks users every minute.
Do not put the date and time in the comment, but use the script I already made for you to get the current Unix Epoch, adding the seconds that the user can navigate.
Whenever the event fires, it reads the current Epoch and closes all users who have an expired Epoch…
So even if everything remains stationary for hours, when it starts again all the expired ones are canceled.
But if you like soluction that do not are really a soluction, but a walktrough for a wrong idea,
set the repat time to 1 min, when routerboard is restarted, it executes all scripts because are scheduled for be repeated after a given date.
But the problem from 23:54:00 to 23:59:59 still exist…
Thanks for your answer friend Rextended, but I didn’t understand anything.
EL DONCITO.

…
…
…
from
" start-date=$adate start-time=$thours]
to
" interval=1m start-date=$adate start-time=$thours]
I already did it friend REX, but you say that I’m wrong in this way, what would be the correct way to avoid problems?
EL DONCITO.
This is what I don’t understand, how do I scropt using this?:
(Do not put the date and time in the comment, but use the script I already made for you to get the current Unix Epoch, adding the seconds that the user can navigate.
Whenever the event fires, it reads the current Epoch and closes all users who have an expired Epoch…
So even if everything remains stationary for hours, when it starts again all the expired ones are canceled.)
EL DONCITO.
Ok, I can write something, but not today, if you do not find a solution, monday I have time to write and test the script
Sure friend REX, anyway here I have the script that you made for me days ago
:local file "firtsstartup.txt"
:local intGoff [:tonum [/system clock get gmt-offset]]
:if ($intGoff > 86400) do={:set intGoff ((4294967296 - $intGoff) * -1)}
:local epochNow (([/tool fetch url="https://helloacm.com/api/unix-timestamp-converter/\3Fs=now" as-value output=user])->"data")
:local upTime [/system resource get uptime]
:local wPos [:find $upTime "w" -1]
:local dPos [:find $upTime "d" -1]
:local utLen [:len $upTime]
:local utSec [:pick $upTime ($utLen - 2) $utLen]
:local utMin [:pick $upTime ($utLen - 5) ($utLen - 3)]
:local utHou [:pick $upTime ($utLen - 8) ($utLen - 6)]
:local utDay 0
:local utWee 0
:if (([:typeof $wPos] = "nil") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime 0 $dPos] }
:if (([:typeof $wPos] = "num") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime ($wPos + 1) $dPos] }
:if ([:typeof $wPos] = "num") do={:set utWee [:pick $upTime 0 $wPos] }
:local totUtSec ($utSec + (60 * $utMin) + (60 * 60 * $utHou) + (60 * 60 * 24 * $utDay) + (60 * 60 * 24 * 7 * $utWee))
:local epochStart ($epochNow - $totUtSec + $intGoff)
:local datetimeStart (([/tool fetch url="https://helloacm.com/api/unix-timestamp-converter/\3Fs=$epochStart" as-value output=user])->"data")
:set datetimeStart [:pick $datetimeStart 1 ([:len $datetimeStart] - 1)]
:local year [:pick $datetimeStart 0 4]
:local month [:pick $datetimeStart 5 7]
:local day [:pick $datetimeStart 8 10]
:local hms [:pick $datetimeStart 11 19]
:local mhours [:tonum [:pick $hms 0 2]]
:local minsec [:pick $hms 2 8]
:local msymbl "AM"
:if ($mhours > 11) do={:set msymbl "PM"}
:set mhours ($mhours % 12)
:if ($mhours = 0) do={:set mhours 12}
:if ($mhours < 10) do={:set mhours "0$mhours"}
:local date "$day/$month/$year"
:local time "$mhours$minsec $msymbl"
:local started "****************************\r\n FIRTSSTARTUP: $date\r\n AT: $time\r\n****************************"
/file
:if ([:len [find where name=$file]] = 0) do={print file=$file; :delay 5; set $file contents=""}
set $file contents=$started
EL DONCITO.
You can schedule simply this, every 10 minutes (I hope 6min are just for test…)
http://forum.mikrotik.com/t/hotspot-cookie-active-problem/159485/1
when you create a user, simply add $epoch + on comment.
for example 6 minutes are (6 × 60) = 360 seconds:
/ip hotspot user
:if ([get $user comment]="") do={
:local epoch (([/tool fetch url="https://helloacm.com/api/unix-timestamp-converter/\3Fs=now" as-value output=user])->"data")
:set epoch ($epoch + 360)
set $user comment=$epoch
}
ok REX, great job, but what about this part of the script
[/system scheduler add name=$user on-event="/ip hotspot user remove \"$user\" \r\
\n/ip hotspot cookie remove [find user=\"$user\"] \r\
\n/system scheduler remove [find name=\"$user\"] \r\
\n\r\
" start-date=$adate start-time=$thours]
to eliminate that user when the 360 seconds have elapsed, and it does not matter that the equipment does not have electricity for many hours and when it starts again, it automatically eliminates it?
EL DOMCITO:
only if you add interval=1m as already wroten
and then how do we delete the expired user…
I don’t understand anything.
EL DONCITO.
This is not good, it is I who do not understand…
Are they scripts that you post in the forum, and you don’t know how they work?
the problem is that when there is a electric cut of several hours, the script does not delete the user, because the date has already passed,
and I have already provided the soluction, add interval=1m to the scheduled event.
I speak Spanish and my English is through the google translator, this is one of the user profiles that I use:
add address-pool=dhcp_pool0 keepalive-timeout=5s mac-cookie-timeout=4h name=2hours on-login=":local time 4h\r\
\n:local atime [ /system clock get time ]\r\
\n:local adate [ /system clock get date ]\r\
\n:local comment \"\$user conected: \$adate at: \$atime\"\r\
\n:local thours (\$atime + \$time)\r\
\n:if ([ /ip hotspot user get \$user comment ]=\"\") do={ [ /ip hotspot user set \$user comment=\$comment ] }\r\
\n\r\
\n[/system scheduler add name=\$user on-event=\"/ip hotspot user remove \\\"\$user\\\" \\r\\\r\
\n \\n/ip hotspot cookie remove [find user=\\\"\$user\\\"] \\r\\\r\
\n \\n/system scheduler remove [find name=\\\"\$user\\\"] \\r\\\r\
\n \\n\\r\\\r\
\n\" start-date=\$adate start-time=\$thours]\r\
\n" rate-limit=256k/1024k
users have 4 hours to spend the internet that I give them, which is two hours, since as you can see in the user profile I use what I call “PAUSED TIME”, that is to say that if for some reason the user decides to leave the hotspot area before his 2 hours are up, when he returns I have the time in which he left, the problem is that if for some reason reason there is an electrc cut and it lasts more than four hours the user will lose his time, so he has not spent his 2 hours, I don’t know if you understand me.
EL DONCITO.
Friends, how do I write the mac cookie timeout in interval of this script and also in interval:
add address-pool=dhcp_pool0 keepalive-timeout=5s mac-cookie-timeout=4h name=2hours on-login=":local time [/ip hotspot user profile get mac-cookie-timeput]
]\r\
\n:local atime [ /system clock get time ]\r\
\n:local adate [ /system clock get date ]\r\
\n:local comment \"\$user conected: \$adate at: \$atime\"\r\
\n:local thours (\$atime + \$time)\r\
\n:if ([ /ip hotspot user get \$user comment ]=\"\") do={ [ /ip hotspot user set \$user comment=\$comment ] }\r\
\n\r\
\n[/system scheduler add name=\$user on-event=\"/ip hotspot user remove \\\"\$user\\\" \\r\\\r\
\n \\n/ip hotspot cookie remove [find user=\\\"\$user\\\"] \\r\\\r\
\n \\n/system scheduler remove [find name=\\\"\$user\\\"] \\r\\\r\
\n \\n\\r\\\r\
\n\" interval=[/ip hotspot user profile get mac-cookie-timeput] start-date=\$adate start-time=\$thours]\r\
\n" rate-limit=256k/1024k
EL DONCITO.
Can anybody help me?
EL DONCITO.
I need your help please.
interval=[/ip hotspot user profile find mac-cookie-timeout name=""]
EL DONCITO.
I already solved
[/ip hotspot user profile get [find where name="XXXX"] mac-cookie-timeout]
Thanks everyone for your help.
EL DONCITO.