Community discussions

MikroTik App
 
letabawireless
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Thu Jul 26, 2012 5:11 pm

User manager delete expired users

Tue Sep 16, 2014 10:24 am

Hi
I have setup the following test Hotspot:
profile with validity of 5m
transfer limit 50m

So, the problem is that, old users pile up. In the real client setup, I have 100's of users, and what I have picked up is that when the start-time parameter gets to the status 'unknown', then it means that the account is expired. I would like to delete these users everyday, by use of a script. However, all of the web interface paramaters does not seem to be available on command line, which is not something Mikrotik normally does. Maybe I am doing something wrong ?

Please help, it is quite a mission to delete the users manually, and unprofessional to expect the client to do this.

Thanks for the help.
 
Abdock
Member Candidate
Member Candidate
Posts: 261
Joined: Sun Sep 25, 2005 10:50 pm

Re: User manager delete expired users

Tue Sep 23, 2014 8:11 pm

 
parinya1957
just joined
Posts: 24
Joined: Mon Mar 11, 2013 6:34 am
Location: Thailand

Re: User manager delete expired users

Wed Oct 01, 2014 5:36 am

Hi letabawireless,

To delete expired user in userman I used below script. You can schedule it to run on period you want but for me I run it once a week because I not have much user. I set user profile for limitation 1day (1d) and 1 month (4w2d) and I saw in user list that when user expired the actual-profile data will empty.

It works on ROS v6.19 for me both RB2011 and R951 but not work on ROS v6.15 (in previous my RB2011 is v6.15 and it not work).
# Automatic remove blank actual-profile user in User Manager for ROS v6.19
:local username

:foreach i in [/tool user-manager user find where !actual-profile] do={
  :set username [/tool user-manager user get $i name]
  :log error ("Remove user name $username")
  [/tool user-manager user remove $i]
}
Hope this will help.
 
letabawireless
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Thu Jul 26, 2012 5:11 pm

Re: User manager delete expired users

Wed Oct 01, 2014 11:52 am

Kudos! That worked great !!
 
enjoy
Frequent Visitor
Frequent Visitor
Posts: 67
Joined: Fri Jul 18, 2008 8:29 pm

Re: User manager delete expired users

Sat Feb 11, 2017 6:03 pm

not running on 6.38.1, why ?
 
Wolfgang
just joined
Posts: 15
Joined: Thu Jan 28, 2016 12:33 pm

Re: User manager delete expired users

Wed Feb 22, 2017 3:44 pm

@ enjoy: Do you run it as scheduled task? What are the rights you set on the script and the task?
 
User avatar
ahmedalmi
Frequent Visitor
Frequent Visitor
Posts: 75
Joined: Sat Sep 13, 2014 5:52 pm
Location: sana'a yemen
Contact:

Re: User manager delete expired users

Sun Apr 30, 2017 12:24 am

this work in 6.38

/tool user-man user remove [find !actual-profile];
 
Hamosal
just joined
Posts: 1
Joined: Thu Oct 19, 2017 6:57 pm

Re: User manager delete expired users

Thu Oct 19, 2017 7:02 pm

/tool user-manager user remove [find where !actual-profile and uptime-used>0s];
 
fernando1787
just joined
Posts: 9
Joined: Mon Apr 11, 2016 6:32 pm

Re: User manager delete expired users

Fri Jan 26, 2018 2:31 am

/tool user-manager user remove [find where !actual-profile and uptime-used>0s];
Hello, I am having same problem, in some circumstances user expires but actual-profile is kept, i.e.: profile validity=1h , uptime-limit=1h, user log in, then close session before uptime-limit, then doesn't start sessions anymore. Profile expire by validity time, but user kept actual-profile value.

I am having problems to find a condition to remove users in this conditions.
 
hardwarematik
just joined
Posts: 3
Joined: Thu May 03, 2018 12:26 am

Re: User manager delete expired users

Thu May 03, 2018 12:36 am

Hi:
I know how to delete users using API in C# with the tik4net unit, it is great unit: IEnumerable<string> command = new string[] { "/tool/user-manager/user/remove", "=numbers=*" + textBox3.Text }, in the textBox3 you can enter the number of the item you want to delete. I'm interesting in to know how delete all the expired users using API with this unit, what should I wirte in my string?

IEnumerable<string> command = new string[] { "/tool/user-manager/user/remove", "[find where !actual-profile and uptime-used>0s]" }

Maybe work?? Because I really dont know how to use "find" command. Thanks in advance
 
hardwarematik
just joined
Posts: 3
Joined: Thu May 03, 2018 12:26 am

Re: User manager delete expired users

Thu May 03, 2018 5:18 pm

this work in 6.38

/tool user-man user remove [find !actual-profile];
Hi:
I know how to delete users using API in C# with the tik4net unit, it is great unit: IEnumerable<string> command = new string[] { "/tool/user-manager/user/remove", "=numbers=*" + textBox3.Text }, in the textBox3 you can enter the number of the item you want to delete. I'm interesting in to know how delete all the expired users using API with this unit, what should I wirte in my string?

IEnumerable<string> command = new string[] { "/tool/user-manager/user/remove", "[find where !actual-profile and uptime-used>0s]" }

Maybe work?? Because I really dont know how to use "find" command. Thanks in advance
 
tawasol4sy
just joined
Posts: 4
Joined: Thu Jul 05, 2018 6:30 am
Contact:

Re: User manager delete expired users

Fri Jul 06, 2018 3:54 pm

Scripts scan cards expired and the validity of their own sessions:

/ Tool user-manager user print brief without-paging;
: Foreach i in = [/ tool user-manager user find where! Actual-profile] do = {
: Local tawasol4sy [/ tool user-manager user remove $ i];
}

https://tawasol4sy.org/%D8%AD%D8%B0%D9% ... -mikrotik/
 
User avatar
kvee
newbie
Posts: 38
Joined: Mon Feb 13, 2023 7:59 pm

Re: User manager delete expired users

Thu Mar 09, 2023 2:55 am

Hi letabawireless,

To delete expired user in userman I used below script. You can schedule it to run on period you want but for me I run it once a week because I not have much user. I set user profile for limitation 1day (1d) and 1 month (4w2d) and I saw in user list that when user expired the actual-profile data will empty.

It works on ROS v6.19 for me both RB2011 and R951 but not work on ROS v6.15 (in previous my RB2011 is v6.15 and it not work).
# Automatic remove blank actual-profile user in User Manager for ROS v6.19
:local username

:foreach i in [/tool user-manager user find where !actual-profile] do={
  :set username [/tool user-manager user get $i name]
  :log error ("Remove user name $username")
  [/tool user-manager user remove $i]
}
Hope this will help.
The updated for RouterOS (tested with 6.49) code:
# Automatic remove blank actual-profile user in User Manager for ROS v6.19
# https://forum.mikrotik.com/viewtopic.php?t=89184#p449692

:local username

:foreach i in [/tool user-manager user find where !actual-profile] do={
    :set username [/tool user-manager user get $i username]
    :log info "script: Remove user name $username"
    [/tool user-manager user remove $i]
};
I don't know what policies is required but it just work.
 
saifulmd0
just joined
Posts: 4
Joined: Wed Mar 22, 2023 3:55 pm
Location: Bangladesh
Contact:

Re: User manager delete expired users

Wed Mar 29, 2023 4:33 pm

All the above codes do not work for RouterOS V7.x
Someone, please help with the updated script for V7.x
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: User manager delete expired users

Wed Mar 29, 2023 7:33 pm

RouterOS 7 do not have user-manager.
What is called "user manager" on v7 is another thing.
 
User avatar
risi
just joined
Posts: 4
Joined: Thu Mar 30, 2023 10:32 am
Location: Eilat Israel
Contact:

Re: User manager delete expired users

Thu Mar 30, 2023 10:55 am

Hi All,
In RouterOS 7 USER-MANAGER is completely different from the previous in RouterOS 6.
The documentation it's not fully complete in this stage.
I need to find a method (script) to delete the expired user with RouterOS 7 (the script I use in RouterOS 6 don't work).
I try to understand the current terminal command, but no Idea how to delete the expired user.
In my specific case I need delete all the User that in User Manager have the total uptime field more to ... (more 1d 00:00:00).
Can anyone have some Idea or script to apply in RouterOS 7?
 
User avatar
risi
just joined
Posts: 4
Joined: Thu Mar 30, 2023 10:32 am
Location: Eilat Israel
Contact:

Re: User manager delete expired users

Wed Apr 05, 2023 10:31 am

Yes OgasaYasu,
User Manager in RouterOS 7 it's really different from the previous version, all the previous script don't work, and the set of command it's now, from my opinion, incomplete.
I use User Manager to manage the User have access form the Hotspot, and usually I create hundred of user automatically from a script or manually.
I need also delete automatically all the user has expired via script, but I don't find any command or script in RouterOS 7.
If someone have some example how to find all the User have the total uptime field more to ... (more 1d 00:00:00), and delete it, I appreciate.

I suggest in future to implement all the command exist in RouterOS 6, and of course the FULL WEB INTERFACE to manage the profile and the user, as soon as possible.
User Manager from my opinion it's a big point of strength from RouterOS and deserve attention from Mikrotik.
 
parinya1957
just joined
Posts: 24
Joined: Mon Mar 11, 2013 6:34 am
Location: Thailand

Re: User manager delete expired users

Tue Apr 18, 2023 1:30 am

Yes OgasaYasu,
User Manager in RouterOS 7 it's really different from the previous version, all the previous script don't work, and the set of command it's now, from my opinion, incomplete.
I use User Manager to manage the User have access form the Hotspot, and usually I create hundred of user automatically from a script or manually.
I need also delete automatically all the user has expired via script, but I don't find any command or script in RouterOS 7.
If someone have some example how to find all the User have the total uptime field more to ... (more 1d 00:00:00), and delete it, I appreciate.

I suggest in future to implement all the command exist in RouterOS 6, and of course the FULL WEB INTERFACE to manage the profile and the user, as soon as possible.
User Manager from my opinion it's a big point of strength from RouterOS and deserve attention from Mikrotik.
Hi risi

Here is my script to delete user in User-manager V7.x. You need to schedule it at lease once a day at any time.
Hope this will help.
#ROS 7.X

:local username
:local userid

# Find state "used" user in user-profile
:foreach i in [/user-manager/user-profile/find state=used] do={
# Find user name and pointer
  :set username [/user-manager/user-profile/get $i user]
  :set userid [/user-manager/user/find name=$username]
# Remove user session if have more than 1 session
  :foreach j in [/user-manager/session/find user=$username] do={
    /user-manager/session/remove $j
  }
# Remove from user-profile
  /user-manager/user-profile/remove $i
# Remove from user
  /user-manager/user/remove $userid
  :log error "$number. Remove User-Manager $username/$userpassword all data.";
}
 
saifulmd0
just joined
Posts: 4
Joined: Wed Mar 22, 2023 3:55 pm
Location: Bangladesh
Contact:

Re: User manager delete expired users

Fri May 19, 2023 11:29 pm

Yes OgasaYasu,
User Manager in RouterOS 7 it's really different from the previous version, all the previous script don't work, and the set of command it's now, from my opinion, incomplete.
I use User Manager to manage the User have access form the Hotspot, and usually I create hundred of user automatically from a script or manually.
I need also delete automatically all the user has expired via script, but I don't find any command or script in RouterOS 7.
If someone have some example how to find all the User have the total uptime field more to ... (more 1d 00:00:00), and delete it, I appreciate.

I suggest in future to implement all the command exist in RouterOS 6, and of course the FULL WEB INTERFACE to manage the profile and the user, as soon as possible.
User Manager from my opinion it's a big point of strength from RouterOS and deserve attention from Mikrotik.
Hi risi

Here is my script to delete user in User-manager V7.x. You need to schedule it at lease once a day at any time.
Hope this will help.
#ROS 7.X

:local username
:local userid

# Find state "used" user in user-profile
:foreach i in [/user-manager/user-profile/find state=used] do={
# Find user name and pointer
  :set username [/user-manager/user-profile/get $i user]
  :set userid [/user-manager/user/find name=$username]
# Remove user session if have more than 1 session
  :foreach j in [/user-manager/session/find user=$username] do={
    /user-manager/session/remove $j
  }
# Remove from user-profile
  /user-manager/user-profile/remove $i
# Remove from user
  /user-manager/user/remove $userid
  :log error "$number. Remove User-Manager $username/$userpassword all data.";
}
Thank you so much Parinya! This script worked perfectly!
 
User avatar
risi
just joined
Posts: 4
Joined: Thu Mar 30, 2023 10:32 am
Location: Eilat Israel
Contact:

Re: User manager delete expired users

Sat May 20, 2023 1:17 pm

THE SCRIPT IS FANTASTIC! WORKING PERFECT! THANK YOU!
 
imirsay
just joined
Posts: 4
Joined: Fri Jul 28, 2023 12:47 pm

Re: User manager delete expired users

Fri Jul 28, 2023 12:53 pm

Yes OgasaYasu,
User Manager in RouterOS 7 it's really different from the previous version, all the previous script don't work, and the set of command it's now, from my opinion, incomplete.
I use User Manager to manage the User have access form the Hotspot, and usually I create hundred of user automatically from a script or manually.
I need also delete automatically all the user has expired via script, but I don't find any command or script in RouterOS 7.
If someone have some example how to find all the User have the total uptime field more to ... (more 1d 00:00:00), and delete it, I appreciate.

I suggest in future to implement all the command exist in RouterOS 6, and of course the FULL WEB INTERFACE to manage the profile and the user, as soon as possible.
User Manager from my opinion it's a big point of strength from RouterOS and deserve attention from Mikrotik.
Hi risi

Here is my script to delete user in User-manager V7.x. You need to schedule it at lease once a day at any time.
Hope this will help.
#ROS 7.X

:local username
:local userid

# Find state "used" user in user-profile
:foreach i in [/user-manager/user-profile/find state=used] do={
# Find user name and pointer
  :set username [/user-manager/user-profile/get $i user]
  :set userid [/user-manager/user/find name=$username]
# Remove user session if have more than 1 session
  :foreach j in [/user-manager/session/find user=$username] do={
    /user-manager/session/remove $j
  }
# Remove from user-profile
  /user-manager/user-profile/remove $i
# Remove from user
  /user-manager/user/remove $userid
  :log error "$number. Remove User-Manager $username/$userpassword all data.";
}


How do I edit this script?
I want them to be deleted after two days

I want usernames that have another active profile not to be deleted
Last edited by imirsay on Fri Jul 28, 2023 2:50 pm, edited 1 time in total.
 
imirsay
just joined
Posts: 4
Joined: Fri Jul 28, 2023 12:47 pm

Re: User manager delete expired users

Fri Jul 28, 2023 1:08 pm


Hi risi

Here is my script to delete user in User-manager V7.x. You need to schedule it at lease once a day at any time.
Hope this will help.

I want usernames that have another active profile not to be deleted

Who is online

Users browsing this forum: No registered users and 8 guests