Community discussions

MikroTik App
 
amobasher
newbie
Topic Author
Posts: 31
Joined: Sun Jul 06, 2014 3:19 pm

script to delete hotspot users after reaching uptime

Sat Jun 25, 2022 1:30 pm

Hi
Need help with the script to delete hotspot users after reaching uptime, the script below doesn't work and it gives me an error as shown in the attachment.
--------------------
/ system script add name="delete user" source={
:foreach i in [/ip hotspot user where uptime=$time and limit-uptime=$time] do={
:if ([/ip hotspot user get $i limit-uptime]<=[/ip hotspot user get $i uptime]) do={
/ip hotspot user remove $i;
}
}
----------------------------
also need to script to be run each 1H automatically.
You do not have the required permissions to view the files attached to this post.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: script to delete hotspot users after reaching uptime

Sat Jun 25, 2022 2:57 pm

missing = between in and [
and /ip hotspot user where where what? find where? (/ip hotspot user find where...)
and $time is undefinded
 
eldoncito2019
Member
Member
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: script to delete hotspot users after reaching uptime

Sat Jun 25, 2022 4:05 pm

I hope this helps:


/ip hotspot user remove [find uptime=01:00:00 limit-uptime=01:00:00]




EL DONCITO.
 
amobasher
newbie
Topic Author
Posts: 31
Joined: Sun Jul 06, 2014 3:19 pm

Re: script to delete hotspot users after reaching uptime

Sat Jun 25, 2022 4:34 pm

missing = between in and [
and /ip hotspot user where where what? find where? (/ip hotspot user find where...)
and $time is undefinded
I'm not familiar with scripting and I try to find my way to get information through research and experience, you point to "Where what"? logically it is supposed to look for "limit-uptime<=uptime", as the attached file correct?
I'm trying to search in Mikrotik scripting but it's not easy to find a proper script that matches my query :(
if you can guide it would be great bro.
You do not have the required permissions to view the files attached to this post.
 
amobasher
newbie
Topic Author
Posts: 31
Joined: Sun Jul 06, 2014 3:19 pm

Re: script to delete hotspot users after reaching uptime

Sat Jun 25, 2022 4:38 pm

I hope this helps:


/ip hotspot user remove [find uptime=01:00:00 limit-uptime=01:00:00]




EL DONCITO.

uptime is variable and it will be useless if I define a script for each user's uptime, need to make the Mikrotik to remove the user whenever the limit-uptime<=uptime
 
amobasher
newbie
Topic Author
Posts: 31
Joined: Sun Jul 06, 2014 3:19 pm

Re: script to delete hotspot users after reaching uptime

Sat Jun 25, 2022 5:43 pm

I hope this helps:
/ip hotspot user remove [find uptime=01:00:00 limit-uptime=01:00:00]
EL DONCITO.
I've tested the following command and it's working :)

/ip hotspot user remove [find uptime<=limit-uptime]
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: script to delete hotspot users after reaching uptime

Sat Jun 25, 2022 7:22 pm

you point to "Where what"? logically it is supposed to look for "limit-uptime<=uptime"
missing "find" between user and where...

And using directly copy & paste without try to understand what is wrong, do not teach you anything (except exercise copy & paste)

And about this:
/ip hotspot user remove [find uptime=01:00:00 limit-uptime=01:00:00]

you can learn only wrong syntax, the correct syntax is:
/ip hotspot user remove [find where uptime=01:00:00 and limit-uptime=01:00:00]

and this is wrong, you can not compare the fields inside the search, is a code parser error that you do not give error:
/ip hotspot user remove [find where uptime<=limit-uptime]
for example you can try:
/ip address print where address!=address
and the terminal print all addresses, regardless if the address is different to himself....
(the 2nd field is treated literally like a string of value "address")
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: script to delete hotspot users after reaching uptime

Tue Jun 28, 2022 9:01 pm

( @eldoncito2019 do not post useless script without any sense just for post something for "I hope it is of some use"... )
 
amobasher
newbie
Topic Author
Posts: 31
Joined: Sun Jul 06, 2014 3:19 pm

Re: script to delete hotspot users after reaching uptime

Wed Jun 29, 2022 1:38 pm

I appreciate your interest and comment on my post ..

It seems that deleting the user according to the uptime is not practical for me after the experiment, but if I added the expiration date in the hotspot user comment, can this user be deleted if the date in the comment is older than the Mikrotik system date?
can this idea scripted somehow?
You do not have the required permissions to view the files attached to this post.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: script to delete hotspot users after reaching uptime

Wed Jun 29, 2022 2:03 pm

MikroTik do not have (for now) usable timestamp like Epoch on Unix and others, and not have datetime format or coherent date format.

Just saving date on comment is useless, because until you do not write functions that compare dates, you can not use that as useful input for any...

You can use this for convert string date to a number, for compare today converted with number saved on comment:
viewtopic.php?p=934798#p934798
 
amobasher
newbie
Topic Author
Posts: 31
Joined: Sun Jul 06, 2014 3:19 pm

Re: script to delete hotspot users after reaching uptime

Wed Jun 29, 2022 2:34 pm

It is frustrating that the router is so powerful, but it lacks some simple things to control the users, the most important of which is the expiry date. Using the user manager, it is not possible to create several users according to a database, but in Winbox, it is just a command that is executed in a few seconds to create 100 users according to an external database as It is in my case.

The biggest challenge for me was how to fetch information from the external database and then export it to Mikrotik and all this was overcome in an Excel file that speaks automatically, including even the command to create the username and login data automatically, but how to clean Mikrotik from old accounts is the challenge for me now.
You do not have the required permissions to view the files attached to this post.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: script to delete hotspot users after reaching uptime

Wed Jun 29, 2022 2:38 pm

You can create users directly inside user-manager from scripts....

You can use room number as username, and a not-so-complex password for users,
and you never need to delete users.

Whit user-manager you can assign profile with times at the room, free or for charge


You can read on comment the date 2022 + 06 + 29, join all togheter 20220629 and compare with date converted by my function if are less or equal...
 
amobasher
newbie
Topic Author
Posts: 31
Joined: Sun Jul 06, 2014 3:19 pm

Re: script to delete hotspot users after reaching uptime

Thu Jun 30, 2022 11:57 am

You can create users directly inside user-manager from scripts....
Appreciate if you shared a script example to convert the below hotspot command to a user manager command

/ip hotspot user
add limit-uptime=14d name=101 password=10965253 profile=Rooms-Double server=hotspot1 comment=101----14-07-2022

the bold text is the validity period for the record which is supposed to be removed at the expiry date in order to add a new record for a new guest with the same room number on the same expiry date of the old record


You can use room number as username, and a not-so-complex password for users,
and you never need to delete users.
Delete is important to clean the data for a smooth audit and to avoid overlap records with the same user name "Room Number"



Whit user-manager you can assign profile with times at the room, free or for charge
Assign profile with time


you mean profile validity? .. the user profile as I saw in user manager needs to assign fixed validity for the profile at the time each room will have different validity from day to another, is there any way to link the user's account validity to the date of the user's check-out from the hotel.




You can read on comment the date 2022 + 06 + 29, join all togheter 20220629 and compare with date converted by my function if are less or equal...

didn't get it :(
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: script to delete hotspot users after reaching uptime

Thu Jun 30, 2022 12:54 pm

You can read on comment the date 2022 + 06 + 29, join all togheter 20220629 and compare with date converted by my function if are less or equal...
didn't get it :(
Sorry, I mean using scripting You can read on comment the date.... etc.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: script to delete hotspot users after reaching uptime

Thu Jun 30, 2022 1:01 pm

example: form this
/ip hotspot user
add limit-uptime=14d name=101 password=10965253 profile=Rooms-Double server=hotspot1 comment="101----14-07-2022"

to this (after configuring customer called "hotel" and profile called "14 days", and what the rest needed)
/tool user-manager user
add disabled=no customer=hotel username=101 password=10965253 shared-users=1 comment="101----14-07-2022"; clear-profiles 101; create-and-activate-profile 101 customer=hotel profile="14 days"

Obviously must be configured all the rest that make hotspot use user-manager users.

Who is online

Users browsing this forum: diamuxin, Google [Bot] and 25 guests