Community discussions

MikroTik App
 
User avatar
TLL
just joined
Topic Author
Posts: 5
Joined: Sun Aug 14, 2022 6:10 am

How to automatically delete expired hotspot users after 7 days expire?

Mon Aug 15, 2022 3:07 am

There is an easy way to clear expired hotspot users automatically (Scheduler), just put this command (Scheduler - On Event): /ip hotspot user remove [find limit-uptime=1s]
The problem is, I don't want to clear those users that just expired only from 1 to 6 days ago. I want to remove expired users for 7 days period or above.

I have this script on the scheduler to make the users expire.
How can I make a script like this but execute "Automatically delete expired hotspot users after 7 days expire"?

I believe, I just need to change the end line command ( :if (($expd < $today and $expt < $curtime) or ... )
But how? I don't learn programming languages.
:local dateint do={:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" );
:local days [ :pick $d 4 6 ];
:local month [ :pick $d 0 3 ];
:local year [ :pick $d 7 11 ];
:local monthint ([ :find $montharray $month]);
:local month ($monthint + 1);
:if ( [len $month] = 1) do={:local zero ("0");:return [:tonum ("$year$zero$month$days")];} else={:return [:tonum ("$year$month$days")];}};
:local timeint do={ :local hours [ :pick $t 0 2 ];
:local minutes [ :pick $t 3 5 ]; :return ($hours * 60 + $minutes) ; };
:local date [ /system clock get date ];
:local time [ /system clock get time ];
:local today [$dateint d=$date];
:local curtime [$timeint t=$time];
:foreach i in [ /ip hotspot user find where profile="PROFILE-A" ] do={ :local comment [ /ip hotspot user get $i comment];
:local name [ /ip hotspot user get $i name];
:local gettime [:pic $comment 12 20]; :if ([:pic $comment 3] = "/" and [:pic $comment 6] = "/") do={:local expd [$dateint d=$comment] ;
:local expt [$timeint t=$gettime];
:if (($expd < $today and $expt < $curtime) or ($expd < $today and $expt > $curtime) or ($expd = $today and $expt < $curtime)) do={ [ /ip hotspot user set limit-uptime=1s $i ]; [ /ip hotspot active remove [find where user=$name] ];}}}

Who is online

Users browsing this forum: No registered users and 18 guests