User manager delete expired users

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.

try this one, http://forum.mikrotik.com/t/solution-automatically-clean-expired-user-manager-accounts/47558/1

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.

Kudos! That worked great !!

not running on 6.38.1, why ?

@ enjoy: Do you run it as scheduled task? What are the rights you set on the script and the task?

this work in 6.38

/tool user-man user remove [find !actual-profile];

/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.

Hi:
I know how to delete users using API in C# with the tik4net unit, it is great unit: IEnumerable 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 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

Hi:
I know how to delete users using API in C# with the tik4net unit, it is great unit: IEnumerable 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 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

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/حذف-الكروت-المنتهية-user-manager-in-mikrotik/

The updated for RouterOS (tested with 6.49) code:

# Automatic remove blank actual-profile user in User Manager for ROS v6.19
# http://forum.mikrotik.com/t/user-manager-delete-expired-users/81006/1

: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.

All the above codes do not work for RouterOS V7.x
Someone, please help with the updated script for V7.x

RouterOS 7 do not have user-manager.
What is called “user manager” on v7 is another thing.

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?

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!

THE SCRIPT IS FANTASTIC! WORKING PERFECT! THANK YOU!