Community discussions

MikroTik App
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Solution: Automatically clean expired User-Manager accounts

Fri Jun 03, 2011 2:05 pm

Finally managed to code it, after a couple of sleepless nights!

I'm sure many people will find this useful, as I've seen quite some requests for this "missing feature".

The problem: User-Manager has no automated way to delete accounts which have gone past their 'credit-till-time' date. In a busy environment such as mine (two Hotels), where 100's of accounts are constantly being generated, the user database can grow to biblical proportions in a short time, since old accounts are never cleaned away.

The solution: What I wanted was something that cycles through all the accounts, compares their 'credit-till-time' date with today's date. If any of them has a date lesser than today, it's deleted. After a few days of tinkering, I have managed to code it.

For clarity's sake, I have made it in a way that if you run it manually through console, you will see the operations in progress and display a summary at the end. If you run it through WinBox, it will only display the final summary and push it to log.

Here it goes. Comments and / or feedback appreciated, as this is the first script that I have ever shared.

NB: Read the included notes!!
# Date: 		03/06/2011
# Revised:		22/02/2013
# Author: 		Alfredo Agius
# File:			cleanUserManager
# Tested on: 	RouterOS version 3.xx
#
# Description: 	Deletes Mikrotik User-Manager accounts whos credit-till-time is less than today's date.
#				Accounts which are not yet activated are skipped.

#				A summary of all accounts skipped, deleted and kept is displayed in the end of the cycle to
#				console screen and to log.
#
# Notes:		This script can be run either from WinBox or from console.
#				-- If console is used, all processing details will be shown, and a summary of operations in the end.
#				-- If WinBox is used, all processing details will be HIDDEN, and a summary of operations will be
#				   sent to log.
#
# Use:			In Winbox, go to System > Script, create a new script, name it cleanUserManager and paste
#				this whole document in it. Click Apply and OK.
#
# Syntax:		To run the script, from terminal enter "/system script run cleanUserManager" without quotes.

:if ([/system ntp client get status]="synchronized") do={

	:global iterator 0
	:global deleted 0
	:global skipped 0
	:global kept 0
	/tool user-manager user print brief without-paging
	:global counter [/tool user-manager user print count-only]

	:do {

		:local thisDate
		:local thisYear
		:local thisDay
		:local thisMonth
		:local thisCredit
		:local creditYear
		:local creditDay
		:local creditMonth
		:local creditName

		:set thisDate [/system clock get date]

		:set thisYear [:pick $thisDate 7 11]
		:set thisDay [:pick $thisDate 4 6]
		:set thisMonth [:pick $thisDate 0 3]

		:if ($thisMonth="jan") do { :set thisMonth "01"}
		:if ($thisMonth="feb") do { :set thisMonth "02"}
		:if ($thisMonth="mar") do { :set thisMonth "03"}
		:if ($thisMonth="apr") do { :set thisMonth "04"}
		:if ($thisMonth="may") do { :set thisMonth "05"}
		:if ($thisMonth="jun") do { :set thisMonth "06"}
		:if ($thisMonth="jul") do { :set thisMonth "07"}
		:if ($thisMonth="aug") do { :set thisMonth "08"}
		:if ($thisMonth="sep") do { :set thisMonth "09"}
		:if ($thisMonth="oct") do { :set thisMonth "10"}
		:if ($thisMonth="nov") do { :set thisMonth "11"}
		:if ($thisMonth="dec") do { :set thisMonth "12"}

		:local thisCredit [/tool user-manager user get $iterator credit-till-time]

		:set creditYear [:pick $thisCredit 7 11]
		:set creditDay [:pick $thisCredit 4 6]
		:set creditMonth [:pick $thisCredit 0 3]
		
		:set creditName [/tool user-manager user get $iterator name]

		:if ($creditMonth="jan") do { :set creditMonth "01"}
		:if ($creditMonth="feb") do { :set creditMonth "02"}
		:if ($creditMonth="mar") do { :set creditMonth "03"}
		:if ($creditMonth="apr") do { :set creditMonth "04"}
		:if ($creditMonth="may") do { :set creditMonth "05"}
		:if ($creditMonth="jun") do { :set creditMonth "06"}
		:if ($creditMonth="jul") do { :set creditMonth "07"}
		:if ($creditMonth="aug") do { :set creditMonth "08"}
		:if ($creditMonth="sep") do { :set creditMonth "09"}
		:if ($creditMonth="oct") do { :set creditMonth "10"}
		:if ($creditMonth="nov") do { :set creditMonth "11"}
		:if ($creditMonth="dec") do { :set creditMonth "12"}
		
		:if ([:len $thisCredit]!=0) do {
			:if ($creditYear>$thisYear) do {
				:put {"Kept username ".$creditName." which expires on ".$thisCredit }; :set kept ($kept+1)} else {:if ($creditYear<$thisYear) do {
				/tool user-manager user remove $creditName; :put {"Deleted username ". $creditName . " which expired on " . $thisCredit}; :set deleted ($deleted+1)} else {:if ($creditMonth>$thisMonth) do {
						:put {"Kept username " . $creditName . " which expires on " . $thisCredit}; :set kept ($kept+1)} else {:if ($creditMonth<$thisMonth) do {
							/tool user-manager user remove $creditName; :put {"Deleted username ". $creditName . " which expired on " . $thisCredit}; :set deleted ($deleted+1)} else {:if ($creditDay>=$thisDay) do {
								:put {"Kept username " . $creditName . " which expires on " . $thisCredit}; :set kept ($kept +1)} else {/tool user-manager user remove $creditName; :put {"Deleted username ". $creditName . " which expired on " . $thisCredit}; :set deleted ($deleted+1)}
						}
					}
				}
			}
		} else {:put {"Username ". $creditName . " is not yet activated. Skipping ..."}; :set skipped ($skipped+1)}
		:set iterator ($iterator+1)} while=($iterator!=$counter)

	:put {"\n\n\r==============================\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t"}
	:put {"Records processed: \t" . $counter}
	:put {"\n\rDeleted usernames: \t" . $deleted}
	:put {"Skipped usernames: \t" . $skipped}
	:put {"Kept usernames:\t\t" . $kept}
	:put {"\n\r==============================\n\r"}

	:log info ("\n\r==============================\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t")
	:log info ("Records processed: \t" . $counter)
	:log info ("\n\rDeleted usernames: \t" . $deleted)
	:log info ("Skipped usernames: \t" . $skipped)
	:log info ("Kept usernames: \t\t" . $kept)
	:log info ("\n\r==============================\n\r")

}

#END OF FILE
Last edited by alfagius on Fri Feb 22, 2013 3:35 pm, edited 4 times in total.
 
mps01k
Frequent Visitor
Frequent Visitor
Posts: 89
Joined: Fri Mar 23, 2007 9:09 pm
Location: HONDURAS
Contact:

Re: Solution: Automatically clean expired User-Manager accou

Tue Jun 07, 2011 8:31 am

thanks i needed this
 
User avatar
JP_Wireless
Member Candidate
Member Candidate
Posts: 276
Joined: Thu Dec 13, 2007 4:31 pm
Location: Lagos Nigeria
Contact:

Re: Solution: Automatically clean expired User-Manager accou

Thu Jun 16, 2011 10:33 pm

This script really looks great! I am going to test it to night on version 4.17, You have done great job in deed from the look of it.
 
reverged
Member Candidate
Member Candidate
Posts: 270
Joined: Thu Nov 12, 2009 8:30 am

Re: Solution: Automatically clean expired User-Manager accou

Fri Jun 17, 2011 1:09 am

Nice job! And useful as well.

I just tried to use this on v5.4 and the user credit-xx functions are gone. ?
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Fri Jun 17, 2011 8:50 am

Thanks for the comments.

I have only tested it on version 3.xx, so I have no idea what changes were done to the user-manager in version 5.

I'll try to install version 5 on a spare Mikrotik when I have a free moment and have a peek at it, however I wouldn't hold my breath as my hands are pretty full right now!
 
User avatar
JP_Wireless
Member Candidate
Member Candidate
Posts: 276
Joined: Thu Dec 13, 2007 4:31 pm
Location: Lagos Nigeria
Contact:

Re: Solution: Automatically clean expired User-Manager accou

Sat Jun 18, 2011 2:57 pm

Nice script! it Works perfect with v4.17, 8)
 
User avatar
petrn
Member Candidate
Member Candidate
Posts: 180
Joined: Thu Jul 29, 2010 3:56 am
Location: Dubai

Re: Solution: Automatically clean expired User-Manager accou

Sat Jun 18, 2011 6:20 pm

Finally managed to code it, after a couple of sleepless nights!
#
# Important:	!! MAKE SURE THAT YOUR CLOCK DATE IS SET CORRECTLY, AS THIS SCRIPT USES IT AS REFERENCE !!
#
# END OF FILE
I think much safer that warning in comment is:
:if ([/system ntp client get status]="synchronized") do={"original script here"}
Everybody not only ISP,WISP should sync their clock.
 
boomdv
just joined
Posts: 15
Joined: Sun Aug 15, 2010 1:58 am

Re: Solution: Automatically clean expired User-Manager accou

Sun Jul 24, 2011 8:40 pm

Is script is make system time sync first before do anything ?

Pls forgive my stupid question. I am a newbie.

Thank.
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Sun Jul 24, 2011 8:49 pm

No. Time syncing is something that you have to do yourself with an NTP time server.
 
boomdv
just joined
Posts: 15
Joined: Sun Aug 15, 2010 1:58 am

Re: Solution: Automatically clean expired User-Manager accou

Sun Jul 24, 2011 9:25 pm

If i want system time sync first after reboot router and don't do anything if sync time is not. What should i do ?
Because I have a problem that some user login after RB reboot and the ntp time is not sync. Pls suggest to me.

Thank you.
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Mon Jul 25, 2011 9:32 am

I think much safer that warning in comment is:
:if ([/system ntp client get status]="synchronized") do={"original script here"}
Everybody not only ISP,WISP should sync their clock.
 
trevorlc1234
just joined
Posts: 19
Joined: Tue May 25, 2010 8:46 am

Re: Solution: Automatically clean expired User-Manager accou

Tue Aug 30, 2011 8:37 pm

Anyway to adjust this script so that it will clear out accounts that expired a month ago and not just today. Some users let their account expire then the next day fill it up again. Want to clean out old accounts that haven't been used for a month? Any pointers would be great as I'm not the best at scripting.
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Tue Aug 30, 2011 9:35 pm

Not sure if I understood what you mean.

This script deletes any account whose expiry date is before today's date. Being yesterday, a month, or a year ago does not matter.

This script in a nutshell is: if expiry_date < today, then delete. Else skip.
 
trevorlc1234
just joined
Posts: 19
Joined: Tue May 25, 2010 8:46 am

Re: Solution: Automatically clean expired User-Manager accou

Tue Aug 30, 2011 9:43 pm

I see. What I was looking for is to limit that.
Example, normally a user would buy time on the hotspot, for say 1 month. They use 1 month and it expires, the script is running daily, when it finds this expired user it wipe out the expired account, but they may want to log back in and refill it the next day. So now they need to recreate their account. It would be good to be able to give it a window and delete only accounts that have been expired for 30+ days.
If the script looked for accounts with 30 days after the expiry date, then removed only those that have been expired for a month, this would be good for those users that let their accounts expire, but then top them up a few days later.
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Tue Aug 30, 2011 9:54 pm

I guess the simplest and crudest way around it, is to +1 on the variable named creditMonth, unless it's 12 (December) where it should change it to 1 (January).

That way you'll be offsetting the expiry that it's checking my 1 month.
 
trevorlc1234
just joined
Posts: 19
Joined: Tue May 25, 2010 8:46 am

Re: Solution: Automatically clean expired User-Manager accou

Tue Aug 30, 2011 10:59 pm

Thanks I will play around with it and give that a shot!
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Tue Aug 30, 2011 11:21 pm

Don't forget to +1 the year too if you switch from December to January :D
 
trevorlc1234
just joined
Posts: 19
Joined: Tue May 25, 2010 8:46 am

Re: Solution: Automatically clean expired User-Manager accou

Tue Aug 30, 2011 11:42 pm

thx!
 
botanik
just joined
Posts: 3
Joined: Thu May 19, 2011 10:31 am

Re: Solution: Automatically clean expired User-Manager accou

Tue Oct 18, 2011 12:00 pm

Hello!
I have this error when trying to run your script :(

[admin@MikroTik] > /system script run cleanUserManager
Flags: X - disabled, A - active, I - incomplete
# NAME LOCATION IP-ADDRESS UPTIME-USED
0 test 3m23s

1
interrupted
input does not match any value of value-name
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Tue Oct 18, 2011 12:40 pm

Is the username "test" created in user-manager, or hotspot?
 
botanik
just joined
Posts: 3
Joined: Thu May 19, 2011 10:31 am

Re: Solution: Automatically clean expired User-Manager accou

Tue Oct 18, 2011 2:12 pm

User "test" created in userman.
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Tue Oct 18, 2011 2:54 pm

Probably, since you're creating the username manually, you don't have a credit-till-time value.

It's what the script is designed to parse, check and delete, so if it doesn't find the value, it errors and aborts.

Try creating a username using its automated batch generator, and making sure you have a validity period.
 
kembiet
Member Candidate
Member Candidate
Posts: 134
Joined: Thu Sep 22, 2011 12:09 pm

Re: Solution: Automatically clean expired User-Manager accou

Sat Dec 17, 2011 12:05 pm

Really really Helpful :D
thz
 
usmany
Member Candidate
Member Candidate
Posts: 144
Joined: Sun Dec 20, 2009 3:20 pm
Location: Nigeria
Contact:

Re: Solution: Automatically clean expired User-Manager accou

Fri Jun 01, 2012 5:48 pm

Hi,

If i may ask please, where do you write or paste the code to?

Run the code /
or
just copy and past in /script
?

Thank you
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Fri Jun 01, 2012 5:52 pm

Due to how the variables are called, you have to put it in a script, and run the script itself.

It also handy to have in a script, as I run it automatically every night at 3am and cleans itself up.
 
usmany
Member Candidate
Member Candidate
Posts: 144
Joined: Sun Dec 20, 2009 3:20 pm
Location: Nigeria
Contact:

Re: Solution: Automatically clean expired User-Manager accou

Fri Jun 01, 2012 6:00 pm

Due to how the variables are called, you have to put it in a script, and run the script itself.

It also handy to have in a script, as I run it automatically every night at 3am and cleans itself up.
Thank you so much, i will try it as well.
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Fri Jun 01, 2012 6:03 pm

Please read the notes at the top of the file thoroughly, as having the right date and time is VERY important.
 
raennik
just joined
Posts: 4
Joined: Wed Aug 08, 2012 1:33 pm

Re: Solution: Automatically clean expired User-Manager accou

Wed Aug 08, 2012 1:38 pm

Hi,

Could you help doing the same thing but instead have it delete the account once it reaches a certain age?
 
Shevron
just joined
Posts: 4
Joined: Sat Jan 19, 2008 1:20 pm

Re: Solution: Automatically clean expired User-Manager accou

Fri Aug 10, 2012 10:51 am

I guess you could, but you'd probably be better off rewriting the whole thing from scratch, rather than modding this one, as this was written with a completely different purpose in mind, so the date comparison routines would be completely different.
 
raennik
just joined
Posts: 4
Joined: Wed Aug 08, 2012 1:33 pm

Re: Solution: Automatically clean expired User-Manager accou

Fri Aug 10, 2012 6:59 pm

Thx, I'll faff around and post new topic on it.
 
User avatar
leemans
Frequent Visitor
Frequent Visitor
Posts: 70
Joined: Thu Apr 07, 2005 12:55 am
Location: Belgium
Contact:

Re: Solution: Automatically clean expired User-Manager accou

Tue Nov 27, 2012 4:32 pm

alfagius,

How to change the 'Automatically clean expired User-Manager accounts' script on this way that only the users accounts will be deleted which meet the following requirements:

last-seen is < today
and Uptime-Used>0
and Till-time=Unknown
and Total-Time-Left=""
and Time-Left=""

Thanks in advance.
Patrick
 
murray654
newbie
Posts: 25
Joined: Sat Sep 15, 2007 1:28 pm
Location: Drakensberg, South Africa
Contact:

Re: Solution: Automatically clean expired User-Manager accou

Wed Dec 19, 2012 11:49 am

Hi

I used this script before, but now it just says:

"
...
1419 xh9p6u

1420
interrupted
input does not match any value of value-name"

My routeros version is 5.7 on rb750

Any way to fix this? Any other solutions?
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Fri Feb 22, 2013 3:36 pm

Added a small update to the original code that queries the status of the NTP client.

It only runs if NTP reports back as "syncronized", therefore avoiding any disasters due to an unset system date.
 
oldsnake
just joined
Posts: 8
Joined: Thu Oct 18, 2012 8:48 am

Re: Solution: Automatically clean expired User-Manager accou

Sun Feb 24, 2013 6:01 am

can i use in user-man v5.17. ?
 
PPJ
newbie
Posts: 36
Joined: Sat Oct 08, 2011 12:55 pm
Location: South Peninsula Cape Town
Contact:

Re: Solution: Automatically clean expired User-Manager accou

Sun Mar 24, 2013 10:07 am

In a process of learning and working I found this script. It runs all the way through ONLY when I remark (#) out this line:

:local thisCredit [/tool user-manager user get $iterator credit-till-time]

From this I think (guess) that the variable "credit-till-time" can not be found or does not exist. The router I am using for test purposes is a RB750 with the latest ROS. ( I use a backup from a live userman installation to test scripts (and RB configs))

I have done a fair amount of looking but can not find a list or document or manual that give all the variables that are available for userman.

I must be looking in the wrong places because if you could find and know about this variable (and others) it must be somewhere??

Can anyone one help me on this one please.
Last edited by PPJ on Sun Mar 24, 2013 10:45 am, edited 1 time in total.
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Sun Mar 24, 2013 10:12 am

I'll have to look into that on the new versions. I will give it a good peek tomorrow at work.

Credit-till-time did exist in userman 3.xx, and it held the date of when an account was bound to expire according to the length of time assigned to it, and it's the foundation on which the whole script is based upon.

Will be bummed if it got removed.

Maybe they changed the name or something. I'll test it let you know :)
 
PPJ
newbie
Posts: 36
Joined: Sat Oct 08, 2011 12:55 pm
Location: South Peninsula Cape Town
Contact:

Re: Solution: Automatically clean expired User-Manager accou

Tue Mar 26, 2013 10:25 am

Thanks alfagius!! :)

If possible, can someone point me to a document listing the variables available for usermanager.
Last edited by PPJ on Thu Apr 18, 2013 7:45 pm, edited 1 time in total.
 
josemari
just joined
Posts: 6
Joined: Tue Oct 16, 2012 1:11 pm
Location: Spain

Re: Solution: Automatically clean expired User-Manager accou

Fri Apr 12, 2013 1:59 pm

Has anyone tested on v5.24?
Thanks.
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Thu Apr 18, 2013 6:24 pm

Tested it. Does not work.

The credit-till-time variable has been removed, much to my annoyance. It was the concept on which this whole script was built.

It's totally useless in 5.xx, and I've been trying to find a workaround. Haven't succeeded so far.

In fact I'm considering going back to 3.xx to get all my functionalities back. This isn't the only thing I'm finding utterly frustrating in 5.xx
 
josemari
just joined
Posts: 6
Joined: Tue Oct 16, 2012 1:11 pm
Location: Spain

Re: Solution: Automatically clean expired User-Manager accou

Fri Apr 19, 2013 10:13 am

Alfagius, thank you very much for all your time and work, and never give up.
Josemari.
 
aleprolit
just joined
Posts: 18
Joined: Thu Apr 11, 2013 11:36 am

Re: Solution: Automatically clean expired User-Manager accou

Thu Aug 01, 2013 3:45 pm

This script work with RouterOS version 6.1
# Date:       03/06/2011
# Revised:      22/02/2013
# Revised:      01/08/2013
# Author:       Alfredo Agius
# Revised by Alexander Prozorov - adaptation for RouterOS version 6.xx
# File:         cleanUserManager
# Tested on:    RouterOS version 6.1
#
# Description:    Deletes Mikrotik User-Manager accounts whos not active more or equal 3 month.
#            Accounts which are not yet activated are skipped.
#            Accounts which have valid profile are skipped.
#            A summary of all accounts skipped, deleted and kept is displayed in the end of the cycle to
#            console screen and to log.
#
# Notes:      
#				This script work if NTP package is installed.
#				This script can be run either from WinBox or from console.
#            -- If console is used, all processing details will be shown, and a summary of operations in the end.
#            -- If WinBox is used, all processing details will be HIDDEN, and a summary of operations will be
#               sent to log.
#
# Use:         In Winbox, go to System > Script, create a new script, name it cleanUserManager and paste
#            this whole document in it. Click Apply and OK.
#
# Syntax:      To run the script, from terminal enter "/system script run cleanUserManager" without quotes.
if ([/system ntp client get status]="synchronized") do={
   :global iterator 0
   :global deleted 0
   :global skipped 0
   :global kept 0
   /tool user-manager user print brief  without-paging
   :global counter [/tool user-manager user print count-only]
   :do {
      :local thisDate
      :local thisYear
      :local thisDay
      :local thisMonth
      :local thisSeen
      :local thisProfile
      :local thisOwner
      :local thisCredit
      :local creditYear
      :local creditDay
      :local creditMonth
      :local expireMonth
      :local creditName
      :set thisDate [/system clock get date]
      :set thisYear [:pick $thisDate 7 11]
      :set thisDay [:pick $thisDate 4 6]
      :set thisMonth [:pick $thisDate 0 3]
      :if ($thisMonth="jan") do { :set thisMonth "01"}
      :if ($thisMonth="feb") do { :set thisMonth "02"}
      :if ($thisMonth="mar") do { :set thisMonth "03"}
      :if ($thisMonth="apr") do { :set thisMonth "04"}
      :if ($thisMonth="may") do { :set thisMonth "05"}
      :if ($thisMonth="jun") do { :set thisMonth "06"}
      :if ($thisMonth="jul") do { :set thisMonth "07"}
      :if ($thisMonth="aug") do { :set thisMonth "08"}
      :if ($thisMonth="sep") do { :set thisMonth "09"}
      :if ($thisMonth="oct") do { :set thisMonth "10"}
      :if ($thisMonth="nov") do { :set thisMonth "11"}
      :if ($thisMonth="dec") do { :set thisMonth "12"}
      :local thisSeen [/tool user-manager user get $iterator last-seen]
      :local thisProfile [/tool user-manager user get $iterator actual-profile]
      :local thisOwner [/tool user-manager user get $iterator customer]
      :set creditName [/tool user-manager user get $iterator name]
      :if ([:len $thisProfile]!=0) do {
      :put {"Username ". $creditName . " Have valid profile:". $thisProfile . " Skipping ..."};
      :set skipped ($skipped+1) } else {
      :if ([$thisSeen]!= "never") do {
      :set creditYear [:pick $thisSeen 7 11]
      :set creditDay [:pick $thisSeen 4 6]
      :set creditMonth [:pick $thisSeen 0 3]
      :if ($creditMonth="jan") do { :set creditMonth "04";:set expireMonth "apr"}
      :if ($creditMonth="feb") do { :set creditMonth "05";:set expireMonth "may"}
      :if ($creditMonth="mar") do { :set creditMonth "06";:set expireMonth "jun"}
      :if ($creditMonth="apr") do { :set creditMonth "07";:set expireMonth "jul"}
      :if ($creditMonth="may") do { :set creditMonth "08";:set expireMonth "aug"}
      :if ($creditMonth="jun") do { :set creditMonth "09";:set expireMonth "sep"}
      :if ($creditMonth="jul") do { :set creditMonth "10";:set expireMonth "oct"}
      :if ($creditMonth="aug") do { :set creditMonth "11";:set expireMonth "nov"}
      :if ($creditMonth="sep") do { :set creditMonth "12";:set expireMonth "dec"}
      :if ($creditMonth="oct") do { :set creditMonth "01";:set expireMonth "jan";:set creditYear ($creditYear+1)}
      :if ($creditMonth="nov") do { :set creditMonth "02";:set expireMonth "feb";:set creditYear ($creditYear+1)}
      :if ($creditMonth="dec") do { :set creditMonth "03";:set expireMonth "mar";:set creditYear ($creditYear+1)} 
	  :set thisCredit ($expireMonth ."/". $creditDay . "/". $creditYear)
      :if ($creditYear>$thisYear) do {
      :put {"Kept username ".$creditName." which expires on ".$thisCredit };
      :set kept ($kept+1) } else {
      :if ($creditYear<$thisYear) do {
      /tool user-manager user remove $creditName;
      :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
      :set deleted ($deleted+1) } else {
      :if ($creditMonth>$thisMonth) do {
      :put {"Kept username " . $creditName . " which expires on " . $thisCredit};
      :set kept ($kept+1) }  else {
      :if ($creditMonth<($thisMonth)) do {
      /tool user-manager user remove $creditName;
      :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
      :set deleted ($deleted+1) } else {
       :if ($creditDay>=$thisDay) do {
       :put {"Kept username " . $creditName . " which expires on " . $thisCredit};
       :set kept ($kept +1) }  else {
        /tool user-manager user remove $creditName;
       :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
       :set deleted ($deleted+1) }
       }
       }
       }
       }
       }  else {
       :put {"Username ". $creditName . " is not yet activated. Skipping ..."};
       :set skipped ($skipped+1)}
       }
       :set iterator ($iterator+1)
       } while=($iterator!=$counter)
   :put {"\n\n\r________________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t"}
   :put {"Records processed: \t" . $counter}
   :put {"\n\rDeleted usernames: \t" . $deleted}
   :put {"Skipped usernames: \t" . $skipped}
   :put {"Kept usernames:\t\t" . $kept}
   :put {"\n\r__________________________________\n\r"}

   :log info ("\n\r_________________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t")
   :log info ("Records processed: \t" . $counter)
   :log info ("\n\rDeleted usernames: \t" . $deleted)
   :log info ("Skipped usernames: \t" . $skipped)
   :log info ("Kept usernames: \t\t" . $kept)
   :log info ("\n\r_________________________________\n\r")

}

#END OF FILE
Last edited by aleprolit on Sat Aug 03, 2013 12:00 pm, edited 3 times in total.
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Thu Aug 01, 2013 3:50 pm

Oh ho!
Thank you, I'll give it a spin!
 
aleprolit
just joined
Posts: 18
Joined: Thu Apr 11, 2013 11:36 am

Re: Solution: Automatically clean expired User-Manager accou

Thu Aug 01, 2013 7:58 pm

and next revision:
It remove users, which registered thru PayPal, but not buy any profile, every time loaded this script and registered users never active after 1 month.
# Date:       03/06/2011
# Revised:      22/02/2013
# Revised:      01/08/2013
# Author:       Alfredo Agius
# Revised by Alexander Prozorov - adaptation for RouterOS version 6.xx 
# Script version (V.2)
# File:         cleanUserManager
# Tested on:    RouterOS version 6.2
#
# Description:    Deletes Mikrotik User-Manager accounts whos not active more or equal 3 month.
#            Accounts which are not yet activated are skipped but removed if not activated 1 month.
#            You must to add to account comment creation date by hand or by script.
#            Accounts which have valid profile are skipped.
#            A summary of all accounts skipped, deleted and kept is displayed in the end of the cycle to
#            console screen and to log.
#
# Notes:      
#            This script work if NTP package is installed.
#            This script can be run either from WinBox or from console.
#            -- If console is used, all processing details will be shown, and a summary of operations in the end.
#            -- If WinBox is used, all processing details will be HIDDEN, and a summary of operations will be
#               sent to log.
#
# Use:         In Winbox, go to System > Script, create a new script, name it cleanUserManager and paste
#            this whole document in it. Click Apply and OK.
#
# Syntax:      To run the script, from terminal enter "/system script run cleanUserManager" without quotes.
if ([/system ntp client get status]="synchronized") do={
   :global iterator 0
   :global deleted 0
   :global skipped 0
   :global kept 0
   /tool user-manager user print brief  without-paging
   :global counter [/tool user-manager user print count-only]
   :do {
      :local thisDate
      :local thisYear
      :local thisDay
      :local thisMonth
      :local thisSeen
      :local thisProfile
      :local thisOwner
      :local thisCredit
      :local creditYear
      :local creditDay
      :local creditMonth
      :local expireMonth
     :local comment
      :local creditName
      :set thisDate [/system clock get date]
      :set thisYear [:pick $thisDate 7 11]
      :set thisDay [:pick $thisDate 4 6]
      :set thisMonth [:pick $thisDate 0 3]
      :if ($thisMonth="jan") do { :set thisMonth "01"}
      :if ($thisMonth="feb") do { :set thisMonth "02"}
      :if ($thisMonth="mar") do { :set thisMonth "03"}
      :if ($thisMonth="apr") do { :set thisMonth "04"}
      :if ($thisMonth="may") do { :set thisMonth "05"}
      :if ($thisMonth="jun") do { :set thisMonth "06"}
      :if ($thisMonth="jul") do { :set thisMonth "07"}
      :if ($thisMonth="aug") do { :set thisMonth "08"}
      :if ($thisMonth="sep") do { :set thisMonth "09"}
      :if ($thisMonth="oct") do { :set thisMonth "10"}
      :if ($thisMonth="nov") do { :set thisMonth "11"}
      :if ($thisMonth="dec") do { :set thisMonth "12"}
      :local thisSeen [/tool user-manager user get $iterator last-seen]
      :local thisProfile [/tool user-manager user get $iterator actual-profile]
      :local thisOwner [/tool user-manager user get $iterator customer]
      :set creditName [/tool user-manager user get $iterator name]
     :set comment [/tool user-manager user get $iterator comment]
      :if ([:len $thisProfile]!=0) do {
      :put {"Username ". $creditName . " Have valid profile:". $thisProfile . " Skipping ..."};
      :set skipped ($skipped+1) } else {
      :if ($thisSeen = "never") do {
	        :set creditYear [:pick $comment 7 11]
       :set creditDay [:pick $comment 4 6]
       :set creditMonth [:pick $comment 0 3]
#2)
      :if ($creditMonth="jan") do { :set creditMonth "02";:set expireMonth "feb"}
       :if ($creditMonth="feb") do { :set creditMonth "03";:set expireMonth "mar"}
       :if ($creditMonth="mar") do { :set creditMonth "04";:set expireMonth "apr"}
       :if ($creditMonth="apr") do { :set creditMonth "05";:set expireMonth "may"}
       :if ($creditMonth="may") do { :set creditMonth "06";:set expireMonth "jun"}
       :if ($creditMonth="jun") do { :set creditMonth "07";:set expireMonth "jul"}
       :if ($creditMonth="jul") do { :set creditMonth "08";:set expireMonth "aug"}
       :if ($creditMonth="aug") do { :set creditMonth "09";:set expireMonth "sep"}
       :if ($creditMonth="sep") do { :set creditMonth "10";:set expireMonth "oct"}
       :if ($creditMonth="oct") do { :set creditMonth "11";:set expireMonth "nov"}
       :if ($creditMonth="nov") do { :set creditMonth "12";:set expireMonth "dec"}
       :if ($creditMonth="dec") do { :set creditMonth "03";:set expireMonth "jan";:set creditYear ($creditYear+1)} 
#2)
      :set thisCredit ($expireMonth ."/". $creditDay . "/". $creditYear)   
      :if ($creditYear>$thisYear) do {
      :put {"Username ". $creditName . " is not yet activated and expires on ".$thisCredit . " Skipping ..."};
       :set skipped ($skipped+1)} else {
       :if ($creditYear<$thisYear) do {
       /tool user-manager user remove $creditName;
       :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
       :set deleted ($deleted+1) } else {
       :if ($creditMonth>$thisMonth) do {
      :put {"Username ". $creditName . " is not yet activated and expires on ".$thisCredit . " Skipping ..."};
       :set skipped ($skipped+1)}  else {
       :if ($creditMonth<($thisMonth)) do {
       /tool user-manager user remove $creditName;
       :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
       :set deleted ($deleted+1) } else {
       :if ($creditDay>=$thisDay) do {
      :put {"Username ". $creditName . " is not yet activated and expires on ".$thisCredit . " Skipping ..."};
       :set skipped ($skipped+1)}  else {
       /tool user-manager user remove $creditName;
       :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
      :set deleted ($deleted+1) }
       }
       }
       }
       }      
	   }  else {	   
      :set creditYear [:pick $thisSeen 7 11]
      :set creditDay [:pick $thisSeen 4 6]
      :set creditMonth [:pick $thisSeen 0 3]
#1)
      :if ($creditMonth="jan") do { :set creditMonth "04";:set expireMonth "apr"}
      :if ($creditMonth="feb") do { :set creditMonth "05";:set expireMonth "may"}
      :if ($creditMonth="mar") do { :set creditMonth "06";:set expireMonth "jun"}
      :if ($creditMonth="apr") do { :set creditMonth "07";:set expireMonth "jul"}
      :if ($creditMonth="may") do { :set creditMonth "08";:set expireMonth "aug"}
      :if ($creditMonth="jun") do { :set creditMonth "09";:set expireMonth "sep"}
      :if ($creditMonth="jul") do { :set creditMonth "10";:set expireMonth "oct"}
      :if ($creditMonth="aug") do { :set creditMonth "11";:set expireMonth "nov"}
      :if ($creditMonth="sep") do { :set creditMonth "12";:set expireMonth "dec"}
      :if ($creditMonth="oct") do { :set creditMonth "01";:set expireMonth "jan";:set creditYear ($creditYear+1)}
      :if ($creditMonth="nov") do { :set creditMonth "02";:set expireMonth "feb";:set creditYear ($creditYear+1)}
      :if ($creditMonth="dec") do { :set creditMonth "03";:set expireMonth "mar";:set creditYear ($creditYear+1)} 
#1)
      :set thisCredit ($expireMonth ."/". $creditDay . "/". $creditYear)
      :if ($creditYear>$thisYear) do {
      :put {"Kept username ".$creditName." which expires on ".$thisCredit };
      :set kept ($kept+1) } else {
      :if ($creditYear<$thisYear) do {
      /tool user-manager user remove $creditName;
      :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
      :set deleted ($deleted+1) } else {
      :if ($creditMonth>$thisMonth) do {
      :put {"Kept username " . $creditName . " which expires on " . $thisCredit};
      :set kept ($kept+1) }  else {
      :if ($creditMonth<($thisMonth)) do {
      /tool user-manager user remove $creditName;
      :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
      :set deleted ($deleted+1) } else {
       :if ($creditDay>=$thisDay) do {
       :put {"Kept username " . $creditName . " which expires on " . $thisCredit};
       :set kept ($kept +1) }  else {
        /tool user-manager user remove $creditName;
       :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
       :set deleted ($deleted+1) }
       }
       }
       }
       }
	   }       
      }
       :set iterator ($iterator+1)
       } while=($iterator!=$counter)
   :put {"\n\n\r________________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t"}
   :put {"Records processed: \t" . $counter}
   :put {"\n\rDeleted usernames: \t" . $deleted}
   :put {"Skipped usernames: \t" . $skipped}
   :put {"Kept usernames:\t\t" . $kept}
   :put {"\n\r_________________________________\n\r"}

   :log info ("\n\r________________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t")
   :log info ("Records processed: \t" . $counter)
   :log info ("\n\rDeleted usernames: \t" . $deleted)
   :log info ("Skipped usernames: \t" . $skipped)
   :log info ("Kept usernames: \t\t" . $kept)
   :log info ("\n\r________________________________\n\r")

}

#END OF FILE
You can edit path marked 1) to change how long account saved in UM DB
and path marked 2) to change how long never active account saved in UM DB.
Load this script from scheduler:
/system scheduler
add interval=1d name=cleanUserManager on-event=cleanUserManager policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-date=\
    dec/08/2010 start-time=02:00:00
Script example for account add with adding date to comment:
(It completed for Lithuania - you can use Google to translate)
<?php
namespace PEAR2\Net\RouterOS;
include_once '../../src/php/PEAR2/Autoload.php';include '../param.common.php';
//../include_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';
?>
<title>Priseregistravimas.</title>
<html>
<head>
<title>Priseregistravimas</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv='Content-Language' content='lt' />
<meta http-equiv='content-style-type' content='text/css' />
<link rel="stylesheet" type="text/css" href="../css.css">
</head>
<?php
if(trim($_POST['email'])=='') {
die("Neįrašėte emailą! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
if(trim($_POST['name'])=='Jūsų abonento vardas.') {
die("Neįrašėte savo vartotojo vardą! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
if(trim($_POST['name'])=='') {
die("Neįrašėte savo vartotojo vardą! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
if(trim($_POST['password'])=='') {
die("Neįrašėte savo slaptažodį! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
if(trim($_POST['password1'])=='') {
die("Neįrašėte pakartotinai slaptažodį! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
if(trim($_POST['phone'])=='') {
die("Neįrašėte savo telefono numerį! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
if(trim($_POST['phone'])=='Jūsų telefono numeris.') {
die("Neįrašėte savo telefono numerį! <br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}&location={$_POST['location']}'> atgal.<br /></a>");
}
else {
echo "";
}
include 'check-phone.php';
$txt1 = 'added by ';
$first = $_POST['first-name'];
$txt2 = ' ';
$last = $_POST['last-name'];
$txt3 = ' !';


   if ('' === $_POST['first-name'])
   {
    $comment = $txt2.'added by User!';
    } else {
	$comment = $txt2.$txt1.$first.$txt2.$last.$txt3;
}
if (isset($_POST['password']) && isset($_POST['password1'])) {
    if ($_POST['password'] !== $_POST['password1']) {
    echo "Slaptažodžiai nesutampa.<br>";
    } else {
$client = new Client($host,$admin,$pass);
$printRequest = new Request('/tool user-manager user print');
$printRequest->setArgument('.proplist', '.id');
$printRequest->setQuery(Query::where('name', $_POST['name']));
$userId = $client->sendSync($printRequest)->getArgument('.id');
    if (null !== $userId ) {
    echo "Vartotojas {$_POST['name']} jau egzistuoja.<br>";
    } else {
    $printRequest = new Request('/tool user-manager user print');
    $printRequest->setArgument('.proplist', '.id');
    $printRequest->setQuery(Query::where('phone', $_POST['phone']));
    $userPh = $client->sendSync($printRequest)->getArgument('.id');
    if (null !== $userPh ) {
    echo "Vartotojas turintis numerį {$_POST['phone']} egzistuoja.<br>";
	} else { 
                  try {$printRequest = new Request('/system clock print');
					   $printRequest->setArgument('.proplist','date');
					   $date = $client->sendSync($printRequest)->getArgument('date');
					   $comment = $date.$comment;
					   $addRequest = new Request('/tool user-manager user add');
                       $addRequest->setArgument('customer',gsm);
                       $addRequest->setArgument('name',$_POST['name']);
					   $addRequest->setArgument('first-name',$_POST['first-name']);
					   $addRequest->setArgument('last-name',$_POST['last-name']);
					   $addRequest->setArgument('location',$_POST['location']);
                       $addRequest->setArgument('email',$_POST['email']);
                       $addRequest->setArgument('password',$_POST['password']);
                       $addRequest->setArgument('phone',$_POST['phone']);
                       $addRequest->setArgument('disabled',no);
                       $addRequest->setArgument('comment', $comment);
                       $addRequest->setArgument('shared-users',1);
                    if ($client->sendSync($addRequest)->getType() !== Response::TYPE_FINAL) {
                       echo "Error when added  '{$_POST['name']}'. Neteisingas e-mail formatas.<br>";
                       } else {
                       echo "Comment: '{$comment}'. Vartotojas'{$_POST['name']}' sėkmingai sukurtas!.";
					   echo "<br />Aktivuoti paslaugą:<a href='../../payment/plan.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&email={$_POST['email']}&phone={$_POST['phone']}'> Spausk čia!</a>";
                                 }
                       } catch(Exception $e) {
                       echo $e;
                       }
	   }
     }
  }
} 
				
echo "<br />Grįžti<a href='index.php?name={$_POST['name']}&loglink={$_POST['linkloginonly']}&first-name={$_POST['first-name']}&last-name={$_POST['last-name']}&location={$_POST['location']}&email={$_POST['email']}&phone={$_POST['phone']}&password={$_POST['password']}'> atgal</a>";
?>
You can see my interface for user add, payment and etc. here Free Net (Lithuanian)
If You have any questions, be free to ask.
Last edited by aleprolit on Mon Aug 12, 2013 10:43 am, edited 7 times in total.
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Thu Aug 01, 2013 8:02 pm

Blimey ... you really took my basic script idea to the next level!
 
aleprolit
just joined
Posts: 18
Joined: Thu Apr 11, 2013 11:36 am

Re: Solution: Automatically clean expired User-Manager accou

Thu Aug 01, 2013 8:11 pm

Спасибо! Будет приятно если это будет кому нибудь полезно...
Thank you! It will be nice if it would be useful to someone ...
 
Abdock
Member Candidate
Member Candidate
Posts: 261
Joined: Sun Sep 25, 2005 10:50 pm

Re: Solution: Automatically clean expired User-Manager accou

Sat Aug 03, 2013 7:43 pm

I tried to run on a 5.25, and got the below error,
input does not match any value of value-name
 
jdg
just joined
Posts: 9
Joined: Tue Aug 06, 2013 4:20 pm

Re: Solution: Automatically clean expired User-Manager accou

Tue Aug 06, 2013 5:09 pm

Very, very nice script! :D
Thank you!
If there were such a script for logs and session of UM, who can delete only old - 2 or 3 monts entries in the log and session...life would become better :)
 
aleprolit
just joined
Posts: 18
Joined: Thu Apr 11, 2013 11:36 am

Re: Solution: Automatically clean expired User-Manager accou

Sun Aug 11, 2013 10:49 pm

To Abdock !
It may be. Script in MT 5.25 and 6.xx have differences.
For example:
I do this script at MT 6.1 and after update to MT 6.2 it stop work, and I must to edit script.
Try to do:
from console run /sys script print
and you can see where is error.
Last edited by aleprolit on Mon Aug 12, 2013 10:46 am, edited 2 times in total.
 
aleprolit
just joined
Posts: 18
Joined: Thu Apr 11, 2013 11:36 am

Re: Solution: Automatically clean expired User-Manager accou

Mon Aug 12, 2013 1:39 am

To jdg .

I think it's possible to include this function to this script or write separate script.
Examples:
1)Script to cleanup logs which oldest than 3 month:
# Date:       03/06/2011
# Revised:      22/02/2013
# Revised:      01/08/2013
# Author:       Alfredo Agius
# Revised by Alexander Prozorov - adaptation for RouterOS version 6.xx 
# Script version (V.2)
# File:         cleanUserLogs
# Tested on:    RouterOS version 6.2
#
# Description:    Deletes Mikrotik User-Manager user logs which age more than 3 month.
#            A summary of all logs deleted and kept is displayed in the end of the cycle to
#            console screen and to log.
#
# Notes:      
#            This script work if NTP package is installed.
#            This script can be run either from WinBox or from console.
#            -- If console is used, all processing details will be shown, and a summary of operations in the end.
#            -- If WinBox is used, all processing details will be HIDDEN, and a summary of operations will be
#               sent to log.
#
# Use:         In Winbox, go to System > Script, create a new script, name it cleanUserLogs and paste
#            this whole document in it. Click Apply and OK.
#
# Syntax:      To run the script, from terminal enter "/system script run cleanUserLogs" without quotes.
if ([/system ntp client get status]="synchronized") do={
   :global deletedL 0
   :global keptL 0
   :global iteratorL 0
   :local thisDate
   :local thisYear
   :local thisDay
   :local thisMonth
   :local thisLog
   :local logSeen
   :local logYear
   :local logDay
   :local logMonth
   :local expireMonth
   :set thisDate [/system clock get date]
   :set thisYear [:pick $thisDate 7 11]
   :set thisDay [:pick $thisDate 4 6]
   :set thisMonth [:pick $thisDate 0 3]
   :if ($thisMonth="jan") do { :set thisMonth "01"}
   :if ($thisMonth="feb") do { :set thisMonth "02"}
   :if ($thisMonth="mar") do { :set thisMonth "03"}
   :if ($thisMonth="apr") do { :set thisMonth "04"}
   :if ($thisMonth="may") do { :set thisMonth "05"}
   :if ($thisMonth="jun") do { :set thisMonth "06"}
   :if ($thisMonth="jul") do { :set thisMonth "07"}
   :if ($thisMonth="aug") do { :set thisMonth "08"}
   :if ($thisMonth="sep") do { :set thisMonth "09"}
   :if ($thisMonth="oct") do { :set thisMonth "10"}
   :if ($thisMonth="nov") do { :set thisMonth "11"}
   :if ($thisMonth="dec") do { :set thisMonth "12"}
   /tool user-manager log print without-paging
   :global counterL [/tool user-manager log print count-only]
   :foreach i in=[/tool user-manager log find] do { 
      :local logSeen [/tool user-manager log get $iteratorL time]
      :set logYear [:pick $logSeen 7 11]
      :set logDay [:pick $logSeen 4 6]
      :set logMonth [:pick $logSeen 0 3]
      :if ($logMonth="jan") do { :set logMonth "04";:set expireMonth "apr"}
      :if ($logMonth="feb") do { :set logMonth "05";:set expireMonth "may"}
      :if ($logMonth="mar") do { :set logMonth "06";:set expireMonth "jun"}
      :if ($logMonth="apr") do { :set logMonth "07";:set expireMonth "jul"}
      :if ($logMonth="may") do { :set logMonth "08";:set expireMonth "aug"}
      :if ($logMonth="jun") do { :set logMonth "09";:set expireMonth "sep"}
      :if ($logMonth="jul") do { :set logMonth "10";:set expireMonth "oct"}
      :if ($logMonth="aug") do { :set logMonth "11";:set expireMonth "nov"}
      :if ($logMonth="sep") do { :set logMonth "12";:set expireMonth "dec"}
      :if ($logMonth="oct") do { :set logMonth "01";:set expireMonth "jan";:set logYear ($logYear+1)}
      :if ($logMonth="nov") do { :set logMonth "02";:set expireMonth "feb";:set logYear ($logYear+1)}
      :if ($logMonth="dec") do { :set logMonth "03";:set expireMonth "mar";:set logYear ($logYear+1)} 
	  :set thisLog ($expireMonth ."/". $logDay . "/". $logYear)
      :if ($logYear>$thisYear) do {
      :put {"Kept log ".$iteratorL." which expires on ".$thisLog };
      :set keptL ($keptL+1) } else {
      :if ($logYear<$thisYear) do {
      /tool user-manager log remove $i; 
      :put {"Deleted log ".$iteratorL. " which expired on ".$thisLog};
      :set deletedL ($deletedL+1) } else {
      :if ($logMonth>$thisMonth) do {
      :put {"Kept log " .$iteratorL. " which expires on ".$thisLog};
      :set keptL ($keptL+1) }  else {
      :if ($logMonth<($thisMonth)) do {
      /tool user-manager log remove $i; 
      :put {"Deleted log ".$iteratorL. " which expired on ".$thisLog};
      :set deletedL ($deletedL+1) } else {
      :if ($logDay>=$thisDay) do {
      :put {"Kept log " .$iteratorL. " which expires on ".$thisLog};
      :set keptL ($keptL +1) }  else {
      /tool user-manager log remove $i; 
      :put {"Deleted log ".$iteratorL. " which expired on ".$thisLog};
      :set deletedL ($deletedL+1) }
      }
      }
      }
      }
	  :set iteratorL ($iteratorL+1);	  
      } 
   :put {"\n\n\r____________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t"}
   :put {"Records processed: \t" . $counterL}
   :put {"\n\rDeleted logs: \t" . $deletedL}
   :put {"Kept logs:\t\t" . $keptL}
   :put {"\n\r______________________________\n\r"}

   :log info ("\n\r_______________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t")
   :log info ("Records processed: \t" . $counterL)
   :log info ("\n\rDeleted logs: \t" . $deletedL)
   :log info ("Kept logs: \t\t" . $keptL)
   :log info ("\n\r_______________________________\n\r")

}
2)Same script to cleanup sessions which oldest than 3 month:
# Date:       03/06/2011
# Revised:      22/02/2013
# Revised:      01/08/2013
# Author:       Alfredo Agius
# Revised by Alexander Prozorov - adaptation for RouterOS version 6.xx 
# Script version (V.2)
# File:         cleanUserSession
# Tested on:    RouterOS version 6.2
#
# Description:    Deletes from Mikrotik User-Manager sessions which age more than 3 month.
#            A summary of all sessions deleted and kept is displayed in the end of the cycle to
#            console screen and to log.
#
# Notes:      
#            This script work if NTP package is installed.
#            This script can be run either from WinBox or from console.
#            -- If console is used, all processing details will be shown, and a summary of operations in the end.
#            -- If WinBox is used, all processing details will be HIDDEN, and a summary of operations will be
#               sent to log.
#
# Use:         In Winbox, go to System > Script, create a new script, name it cleanUserSession and paste
#            this whole document in it. Click Apply and OK.
#
# Syntax:      To run the script, from terminal enter "/system script run cleanUserSession" without quotes.
if ([/system ntp client get status]="synchronized") do={
   :global deletedS 0
   :global keptS 0
   :global iteratorS 0
   :local thisDate
   :local thisYear
   :local thisDay
   :local thisMonth
   :local thisLog
   :local logSeen
   :local logYear
   :local logDay
   :local logMonth
   :local expireMonth
   :set thisDate [/system clock get date]
   :set thisYear [:pick $thisDate 7 11]
   :set thisDay [:pick $thisDate 4 6]
   :set thisMonth [:pick $thisDate 0 3]
   :if ($thisMonth="jan") do { :set thisMonth "01"}
   :if ($thisMonth="feb") do { :set thisMonth "02"}
   :if ($thisMonth="mar") do { :set thisMonth "03"}
   :if ($thisMonth="apr") do { :set thisMonth "04"}
   :if ($thisMonth="may") do { :set thisMonth "05"}
   :if ($thisMonth="jun") do { :set thisMonth "06"}
   :if ($thisMonth="jul") do { :set thisMonth "07"}
   :if ($thisMonth="aug") do { :set thisMonth "08"}
   :if ($thisMonth="sep") do { :set thisMonth "09"}
   :if ($thisMonth="oct") do { :set thisMonth "10"}
   :if ($thisMonth="nov") do { :set thisMonth "11"}
   :if ($thisMonth="dec") do { :set thisMonth "12"}
   /tool user-manager session print without-paging
   :global counterS [/tool user-manager session print count-only]
   :foreach i in=[/tool user-manager session find] do { 
      :local logSeen [/tool user-manager session get $iteratorS till-time]
      :set logYear [:pick $logSeen 7 11]
      :set logDay [:pick $logSeen 4 6]
      :set logMonth [:pick $logSeen 0 3]
      :if ($logMonth="jan") do { :set logMonth "04";:set expireMonth "apr"}
      :if ($logMonth="feb") do { :set logMonth "05";:set expireMonth "may"}
      :if ($logMonth="mar") do { :set logMonth "06";:set expireMonth "jun"}
      :if ($logMonth="apr") do { :set logMonth "07";:set expireMonth "jul"}
      :if ($logMonth="may") do { :set logMonth "08";:set expireMonth "aug"}
      :if ($logMonth="jun") do { :set logMonth "09";:set expireMonth "sep"}
      :if ($logMonth="jul") do { :set logMonth "10";:set expireMonth "oct"}
      :if ($logMonth="aug") do { :set logMonth "11";:set expireMonth "nov"}
      :if ($logMonth="sep") do { :set logMonth "12";:set expireMonth "dec"}
      :if ($logMonth="oct") do { :set logMonth "01";:set expireMonth "jan";:set logYear ($logYear+1)}
      :if ($logMonth="nov") do { :set logMonth "02";:set expireMonth "feb";:set logYear ($logYear+1)}
      :if ($logMonth="dec") do { :set logMonth "03";:set expireMonth "mar";:set logYear ($logYear+1)} 
	  :set thisLog ($expireMonth ."/". $logDay . "/". $logYear)
      :if ($logYear>$thisYear) do {
      :put {"Kept session ".$iteratorS." which expires on ".$thisLog };
      :set keptS ($keptS+1) } else {
      :if ($logYear<$thisYear) do {
      /tool user-manager session remove $i; 
      :put {"Deleted session ".$iteratorS. " which expired on ".$thisLog};
      :set deletedS ($deletedS+1) } else {
      :if ($logMonth>$thisMonth) do {
      :put {"Kept session " .$iteratorS. " which expires on ".$thisLog};
      :set keptS ($keptS+1) }  else {
      :if ($logMonth<($thisMonth)) do {
      /tool user-manager session remove $i; 
      :put {"Deleted session ".$iteratorS. " which expired on ".$thisLog};
      :set deletedS ($deletedS+1) } else {
      :if ($logDay>=$thisDay) do {
      :put {"Kept session " .$iteratorS. " which expires on ".$thisLog};
      :set keptS ($keptS +1) }  else {
      /tool user-manager session remove $i; 
      :put {"Deleted session ".$iteratorS. " which expired on ".$thisLog};
      :set deletedS ($deletedS+1) }
      }
      }
      }
      }
	  :set iteratorS ($iteratorS+1);	  
      } 
   :put {"\n\n\r____________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t"}
   :put {"Records processed: \t" . $counterS}
   :put {"\n\rDeleted sessions: \t" . $deletedS}
   :put {"Kept sessions:\t\t" . $keptS}
   :put {"\n\r______________________________\n\r"}

   :log info ("\n\r_______________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t")
   :log info ("Records processed: \t" . $counterS)
   :log info ("\n\rDeleted sessions: \t" . $deletedS)
   :log info ("Kept sessions: \t\t" . $keptS)
   :log info ("\n\r_______________________________\n\r")

}
 
aleprolit
just joined
Posts: 18
Joined: Thu Apr 11, 2013 11:36 am

Re: Solution: Automatically clean expired User-Manager accou

Wed Aug 14, 2013 11:48 am

And script for UM DB backup to external FTP server:
# automated Um  backup  to External FTP
#File name:Um-FTP-Backup
# Get time
:local ts [/system clock get time]
:set ts ([:pick $ts 0 2].[:pick $ts 3 5].[:pick $ts 6 8])
# Get Date
:local ds [/system clock get date]
:local month
   :set month [:pick $ds 0 3]
   :if ($month="jan") do { :set month "01"}
   :if ($month="feb") do { :set month "02"}
   :if ($month="mar") do { :set month "03"}
   :if ($month="apr") do { :set month "04"}
   :if ($month="may") do { :set month "05"}
   :if ($month="jun") do { :set month "06"}
   :if ($month="jul") do { :set month "07"}
   :if ($month="aug") do { :set month "08"}
   :if ($month="sep") do { :set month "09"}
   :if ($month="oct") do { :set month "10"}
   :if ($month="nov") do { :set month "11"}
   :if ($month="dec") do { :set month "12"}

:set ds ([:pick $ds 7 11]."_".$month."_".[:pick $ds 4 6])
# This line to generate the file name for System backup - file name will be User_Manager- ServerName? - Date? - Time?
#:local fname ("/_User_Manager_".[/system identity get name]."_".$ds."_".$ts.".umb")
:local fname ("/_User_Manager_".$ds."_".$ts.".umb")
/tool user-manager database save name=$fname
:log info message=UmBackupFinished;
# Upload the System Backup to External FTP - change address to your ftp server + user + pass+upload_path
/tool fetch address="192.168.x.y" user="user" password="password" mode=ftp src-path="$fname" dst-path="upload_path/$fname" upload=yes
:delay 60s;
:foreach i in=[/file find] do={:if ([:typeof [:find [/file get $i name] "_User_Manager_"]]!="nil") do={/file remove $i}}
:log info message=SystemBackup-TempRemoved;
:log info message=SystemBackup-Finished;

You must add schedule for all scripts:
/system scheduler
add interval=1d name=Um-FTP-Backup on-event=Um-FTP-Backup policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-date=dec/08/2010 start-time=01:00:00
add interval=1d name=cleanUserManager on-event=cleanUserManager policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-date=dec/08/2010 start-time=02:00:00
add interval=1d name=cleanUserLogs on-event=cleanUserLogs policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-date=dec/08/2010 start-time=02:30:00
add interval=1d name=cleanUserSession on-event=cleanUserSession policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-date=dec/08/2010 start-time=03:00:00
Last edited by aleprolit on Thu Sep 26, 2013 10:56 am, edited 1 time in total.
 
jdg
just joined
Posts: 9
Joined: Tue Aug 06, 2013 4:20 pm

Re: Solution: Automatically clean expired User-Manager accou

Fri Aug 16, 2013 5:18 pm

Thank you! I'll try it and then post!
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accou

Mon Aug 19, 2013 10:44 am

Makes me very happy to have started this, seeing how it's evolving :D

It was so much needed in UM!

Thank to all those who are contributing, and giving feedback.
 
User avatar
vipe
Member Candidate
Member Candidate
Posts: 166
Joined: Thu Sep 14, 2006 10:05 pm

Re: Solution: Automatically clean expired User-Manager accou

Tue Sep 24, 2013 8:12 am

:D
this Script very good!
 
Fleury
just joined
Posts: 8
Joined: Sun Mar 31, 2013 2:47 pm

Re: Solution: Automatically clean expired User-Manager accou

Sun Nov 10, 2013 11:21 pm

Did someone get a script working with 5.4?
 
jdg
just joined
Posts: 9
Joined: Tue Aug 06, 2013 4:20 pm

Re: Solution: Automatically clean expired User-Manager accou

Sun Dec 29, 2013 8:50 pm

I used script above a while, but for several reasons I have to use this script:

:global deleted 0;
:global skipped 0;
:global counter 0;
:log info ("\n\r_________________________________\n\n\rCleaning users ready!\n\n\rPerformed these operations:")
/tool user-manager user print brief without-paging;
:foreach i in=[/tool user-manager user find] do={
:local thisProfile [/tool user-manager user get $i actual-profile];
:local creditName [/tool user-manager user get $i name];
:if ([:len $thisProfile]!=0) do={
:put {"Username ". $creditName . " Have valid profile:". $thisProfile . " Skipping ..."};
:set skipped ($skipped+1)} else={
/tool user-manager user remove $creditName;
:put {"Delete username: \t" . $creditName}
:log info ("Delete username: \t" . $creditName)
:set deleted ($deleted+1)};
:set counter ($counter+1);
}
:put {"\n\n\r________________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t"};
:put {"Records processed: \t" . $counter};
:put {"\n\rDeleted usernames: \t" . $deleted};
:put {"Skipped usernames: \t" . $skipped};
:put {"\n\r__________________________________\n\r"};
:log info ("Records processed: \t" . $counter)
:log info ("Deleted usernames: \t" . $deleted)
:log info ("Skipped usernames: \t" . $skipped)
:log info ("_________________________________\n\r")


It's work good, but sometime fails to delete expires users from UM DB. In the log is the line, for example:
"Delete username: xyz"
but realy user xyz and all expires users after xyz is not deleted from UM DB.
The solution is to manually delete users from userman web page tool. Then the script works normally until any strange user who is not deleted from the database.
Any help, please?
 
jdg
just joined
Posts: 9
Joined: Tue Aug 06, 2013 4:20 pm

Re: Solution: Automatically clean expired User-Manager accou

Fri Jan 03, 2014 9:43 am

Any help from mikrotik support team, please!
 
jdg
just joined
Posts: 9
Joined: Tue Aug 06, 2013 4:20 pm

Re: Solution: Automatically clean expired User-Manager accou

Thu Feb 20, 2014 1:29 pm

Finaly this script working for me:

:global iterator 0
:global deleted 0;
:global skipped 0;
:global counter [/tool user-manager user print count-only]
:log info ("\n\r_________________________________\n\n\rCleaning users ready!\n\n\rPerformed these operations:")
/tool user-manager user print brief without-paging;
:do {
:local thisProfile [/tool user-manager user get $iterator actual-profile]
:local creditName [/tool user-manager user get $iterator name]
:if ([:len $thisProfile]!=0) do={
:put {"Username ". $creditName . " Have valid profile:". $thisProfile . " Skipping ..."};
:set skipped ($skipped+1)} else={
/tool user-manager user remove $iterator;
:put {"Delete username: \t" . $creditName}
:log info ("Delete username: \t" . $creditName)
:set deleted ($deleted+1)};
:set iterator ($iterator+1)
} while=($iterator!=$counter)
:put {"\n\n\r________________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t"};
:put {"Records processed: \t" . $counter};
:put {"\n\rDeleted usernames: \t" . $deleted};
:put {"Skipped usernames: \t" . $skipped};
:put {"\n\r__________________________________\n\r"};
:log info ("Records processed: \t" . $counter)
:log info ("Deleted usernames: \t" . $deleted)
:log info ("Skipped usernames: \t" . $skipped)
:log info ("_________________________________\n\r")
 
aonallah
just joined
Posts: 6
Joined: Thu Sep 11, 2014 2:22 am

Re: Solution: Automatically clean expired User-Manager accou

Sun Sep 21, 2014 9:35 pm

This script work with RouterOS version 6.1
# Date:       03/06/2011
# Revised:      22/02/2013
# Revised:      01/08/2013
# Author:       Alfredo Agius
# Revised by Alexander Prozorov - adaptation for RouterOS version 6.xx
# File:         cleanUserManager
# Tested on:    RouterOS version 6.1
#
# Description:    Deletes Mikrotik User-Manager accounts whos not active more or equal 3 month.
#            Accounts which are not yet activated are skipped.
#            Accounts which have valid profile are skipped.
#            A summary of all accounts skipped, deleted and kept is displayed in the end of the cycle to
#            console screen and to log.
#
# Notes:      
#				This script work if NTP package is installed.
#				This script can be run either from WinBox or from console.
#            -- If console is used, all processing details will be shown, and a summary of operations in the end.
#            -- If WinBox is used, all processing details will be HIDDEN, and a summary of operations will be
#               sent to log.
#
# Use:         In Winbox, go to System > Script, create a new script, name it cleanUserManager and paste
#            this whole document in it. Click Apply and OK.
#
# Syntax:      To run the script, from terminal enter "/system script run cleanUserManager" without quotes.
if ([/system ntp client get status]="synchronized") do={
   :global iterator 0
   :global deleted 0
   :global skipped 0
   :global kept 0
   /tool user-manager user print brief  without-paging
   :global counter [/tool user-manager user print count-only]
   :do {
      :local thisDate
      :local thisYear
      :local thisDay
      :local thisMonth
      :local thisSeen
      :local thisProfile
      :local thisOwner
      :local thisCredit
      :local creditYear
      :local creditDay
      :local creditMonth
      :local expireMonth
      :local creditName
      :set thisDate [/system clock get date]
      :set thisYear [:pick $thisDate 7 11]
      :set thisDay [:pick $thisDate 4 6]
      :set thisMonth [:pick $thisDate 0 3]
      :if ($thisMonth="jan") do { :set thisMonth "01"}
      :if ($thisMonth="feb") do { :set thisMonth "02"}
      :if ($thisMonth="mar") do { :set thisMonth "03"}
      :if ($thisMonth="apr") do { :set thisMonth "04"}
      :if ($thisMonth="may") do { :set thisMonth "05"}
      :if ($thisMonth="jun") do { :set thisMonth "06"}
      :if ($thisMonth="jul") do { :set thisMonth "07"}
      :if ($thisMonth="aug") do { :set thisMonth "08"}
      :if ($thisMonth="sep") do { :set thisMonth "09"}
      :if ($thisMonth="oct") do { :set thisMonth "10"}
      :if ($thisMonth="nov") do { :set thisMonth "11"}
      :if ($thisMonth="dec") do { :set thisMonth "12"}
      :local thisSeen [/tool user-manager user get $iterator last-seen]
      :local thisProfile [/tool user-manager user get $iterator actual-profile]
      :local thisOwner [/tool user-manager user get $iterator customer]
      :set creditName [/tool user-manager user get $iterator name]
      :if ([:len $thisProfile]!=0) do {
      :put {"Username ". $creditName . " Have valid profile:". $thisProfile . " Skipping ..."};
      :set skipped ($skipped+1) } else {
      :if ([$thisSeen]!= "never") do {
      :set creditYear [:pick $thisSeen 7 11]
      :set creditDay [:pick $thisSeen 4 6]
      :set creditMonth [:pick $thisSeen 0 3]
      :if ($creditMonth="jan") do { :set creditMonth "04";:set expireMonth "apr"}
      :if ($creditMonth="feb") do { :set creditMonth "05";:set expireMonth "may"}
      :if ($creditMonth="mar") do { :set creditMonth "06";:set expireMonth "jun"}
      :if ($creditMonth="apr") do { :set creditMonth "07";:set expireMonth "jul"}
      :if ($creditMonth="may") do { :set creditMonth "08";:set expireMonth "aug"}
      :if ($creditMonth="jun") do { :set creditMonth "09";:set expireMonth "sep"}
      :if ($creditMonth="jul") do { :set creditMonth "10";:set expireMonth "oct"}
      :if ($creditMonth="aug") do { :set creditMonth "11";:set expireMonth "nov"}
      :if ($creditMonth="sep") do { :set creditMonth "12";:set expireMonth "dec"}
      :if ($creditMonth="oct") do { :set creditMonth "01";:set expireMonth "jan";:set creditYear ($creditYear+1)}
      :if ($creditMonth="nov") do { :set creditMonth "02";:set expireMonth "feb";:set creditYear ($creditYear+1)}
      :if ($creditMonth="dec") do { :set creditMonth "03";:set expireMonth "mar";:set creditYear ($creditYear+1)} 
	  :set thisCredit ($expireMonth ."/". $creditDay . "/". $creditYear)
      :if ($creditYear>$thisYear) do {
      :put {"Kept username ".$creditName." which expires on ".$thisCredit };
      :set kept ($kept+1) } else {
      :if ($creditYear<$thisYear) do {
      /tool user-manager user remove $creditName;
      :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
      :set deleted ($deleted+1) } else {
      :if ($creditMonth>$thisMonth) do {
      :put {"Kept username " . $creditName . " which expires on " . $thisCredit};
      :set kept ($kept+1) }  else {
      :if ($creditMonth<($thisMonth)) do {
      /tool user-manager user remove $creditName;
      :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
      :set deleted ($deleted+1) } else {
       :if ($creditDay>=$thisDay) do {
       :put {"Kept username " . $creditName . " which expires on " . $thisCredit};
       :set kept ($kept +1) }  else {
        /tool user-manager user remove $creditName;
       :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
       :set deleted ($deleted+1) }
       }
       }
       }
       }
       }  else {
       :put {"Username ". $creditName . " is not yet activated. Skipping ..."};
       :set skipped ($skipped+1)}
       }
       :set iterator ($iterator+1)
       } while=($iterator!=$counter)
   :put {"\n\n\r________________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t"}
   :put {"Records processed: \t" . $counter}
   :put {"\n\rDeleted usernames: \t" . $deleted}
   :put {"Skipped usernames: \t" . $skipped}
   :put {"Kept usernames:\t\t" . $kept}
   :put {"\n\r__________________________________\n\r"}

   :log info ("\n\r_________________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t")
   :log info ("Records processed: \t" . $counter)
   :log info ("\n\rDeleted usernames: \t" . $deleted)
   :log info ("Skipped usernames: \t" . $skipped)
   :log info ("Kept usernames: \t\t" . $kept)
   :log info ("\n\r_________________________________\n\r")

}

#END OF FILE
my mikrotik on pc ... v 5.20 x86

I used scripts above, but no any result and no error!!!?????!!!!
Any help from mikrotik support team,
please!
 
Jaggl
just joined
Posts: 24
Joined: Mon Aug 27, 2012 3:00 pm

Re: Solution: Automatically clean expired User-Manager accou

Sun Dec 28, 2014 7:27 pm

To jdg .

I think it's possible to include this function to this script or write separate script.
Examples:
1)Script to cleanup logs which oldest than 3 month:
# Date:       03/06/2011
# Revised:      22/02/2013
# Revised:      01/08/2013
# Author:       Alfredo Agius
# Revised by Alexander Prozorov - adaptation for RouterOS version 6.xx 
# Script version (V.2)
# File:         cleanUserLogs
# Tested on:    RouterOS version 6.2
#
# Description:    Deletes Mikrotik User-Manager user logs which age more than 3 month.
#            A summary of all logs deleted and kept is displayed in the end of the cycle to
#            console screen and to log.
#
# Notes:      
#            This script work if NTP package is installed.
#            This script can be run either from WinBox or from console.
#            -- If console is used, all processing details will be shown, and a summary of operations in the end.
#            -- If WinBox is used, all processing details will be HIDDEN, and a summary of operations will be
#               sent to log.
#
# Use:         In Winbox, go to System > Script, create a new script, name it cleanUserLogs and paste
#            this whole document in it. Click Apply and OK.
#
# Syntax:      To run the script, from terminal enter "/system script run cleanUserLogs" without quotes.
if ([/system ntp client get status]="synchronized") do={
   :global deletedL 0
   :global keptL 0
   :global iteratorL 0
   :local thisDate
   :local thisYear
   :local thisDay
   :local thisMonth
   :local thisLog
   :local logSeen
   :local logYear
   :local logDay
   :local logMonth
   :local expireMonth
   :set thisDate [/system clock get date]
   :set thisYear [:pick $thisDate 7 11]
   :set thisDay [:pick $thisDate 4 6]
   :set thisMonth [:pick $thisDate 0 3]
   :if ($thisMonth="jan") do { :set thisMonth "01"}
   :if ($thisMonth="feb") do { :set thisMonth "02"}
   :if ($thisMonth="mar") do { :set thisMonth "03"}
   :if ($thisMonth="apr") do { :set thisMonth "04"}
   :if ($thisMonth="may") do { :set thisMonth "05"}
   :if ($thisMonth="jun") do { :set thisMonth "06"}
   :if ($thisMonth="jul") do { :set thisMonth "07"}
   :if ($thisMonth="aug") do { :set thisMonth "08"}
   :if ($thisMonth="sep") do { :set thisMonth "09"}
   :if ($thisMonth="oct") do { :set thisMonth "10"}
   :if ($thisMonth="nov") do { :set thisMonth "11"}
   :if ($thisMonth="dec") do { :set thisMonth "12"}
   /tool user-manager log print without-paging
   :global counterL [/tool user-manager log print count-only]
   :foreach i in=[/tool user-manager log find] do { 
      :local logSeen [/tool user-manager log get $iteratorL time]
      :set logYear [:pick $logSeen 7 11]
      :set logDay [:pick $logSeen 4 6]
      :set logMonth [:pick $logSeen 0 3]
      :if ($logMonth="jan") do { :set logMonth "04";:set expireMonth "apr"}
      :if ($logMonth="feb") do { :set logMonth "05";:set expireMonth "may"}
      :if ($logMonth="mar") do { :set logMonth "06";:set expireMonth "jun"}
      :if ($logMonth="apr") do { :set logMonth "07";:set expireMonth "jul"}
      :if ($logMonth="may") do { :set logMonth "08";:set expireMonth "aug"}
      :if ($logMonth="jun") do { :set logMonth "09";:set expireMonth "sep"}
      :if ($logMonth="jul") do { :set logMonth "10";:set expireMonth "oct"}
      :if ($logMonth="aug") do { :set logMonth "11";:set expireMonth "nov"}
      :if ($logMonth="sep") do { :set logMonth "12";:set expireMonth "dec"}
      :if ($logMonth="oct") do { :set logMonth "01";:set expireMonth "jan";:set logYear ($logYear+1)}
      :if ($logMonth="nov") do { :set logMonth "02";:set expireMonth "feb";:set logYear ($logYear+1)}
      :if ($logMonth="dec") do { :set logMonth "03";:set expireMonth "mar";:set logYear ($logYear+1)} 
	  :set thisLog ($expireMonth ."/". $logDay . "/". $logYear)
      :if ($logYear>$thisYear) do {
      :put {"Kept log ".$iteratorL." which expires on ".$thisLog };
      :set keptL ($keptL+1) } else {
      :if ($logYear<$thisYear) do {
      /tool user-manager log remove $i; 
      :put {"Deleted log ".$iteratorL. " which expired on ".$thisLog};
      :set deletedL ($deletedL+1) } else {
      :if ($logMonth>$thisMonth) do {
      :put {"Kept log " .$iteratorL. " which expires on ".$thisLog};
      :set keptL ($keptL+1) }  else {
      :if ($logMonth<($thisMonth)) do {
      /tool user-manager log remove $i; 
      :put {"Deleted log ".$iteratorL. " which expired on ".$thisLog};
      :set deletedL ($deletedL+1) } else {
      :if ($logDay>=$thisDay) do {
      :put {"Kept log " .$iteratorL. " which expires on ".$thisLog};
      :set keptL ($keptL +1) }  else {
      /tool user-manager log remove $i; 
      :put {"Deleted log ".$iteratorL. " which expired on ".$thisLog};
      :set deletedL ($deletedL+1) }
      }
      }
      }
      }
	  :set iteratorL ($iteratorL+1);	  
      } 
   :put {"\n\n\r____________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t"}
   :put {"Records processed: \t" . $counterL}
   :put {"\n\rDeleted logs: \t" . $deletedL}
   :put {"Kept logs:\t\t" . $keptL}
   :put {"\n\r______________________________\n\r"}

   :log info ("\n\r_______________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t")
   :log info ("Records processed: \t" . $counterL)
   :log info ("\n\rDeleted logs: \t" . $deletedL)
   :log info ("Kept logs: \t\t" . $keptL)
   :log info ("\n\r_______________________________\n\r")

}
2)Same script to cleanup sessions which oldest than 3 month:
# Date:       03/06/2011
# Revised:      22/02/2013
# Revised:      01/08/2013
# Author:       Alfredo Agius
# Revised by Alexander Prozorov - adaptation for RouterOS version 6.xx 
# Script version (V.2)
# File:         cleanUserSession
# Tested on:    RouterOS version 6.2
#
# Description:    Deletes from Mikrotik User-Manager sessions which age more than 3 month.
#            A summary of all sessions deleted and kept is displayed in the end of the cycle to
#            console screen and to log.
#
# Notes:      
#            This script work if NTP package is installed.
#            This script can be run either from WinBox or from console.
#            -- If console is used, all processing details will be shown, and a summary of operations in the end.
#            -- If WinBox is used, all processing details will be HIDDEN, and a summary of operations will be
#               sent to log.
#
# Use:         In Winbox, go to System > Script, create a new script, name it cleanUserSession and paste
#            this whole document in it. Click Apply and OK.
#
# Syntax:      To run the script, from terminal enter "/system script run cleanUserSession" without quotes.
if ([/system ntp client get status]="synchronized") do={
   :global deletedS 0
   :global keptS 0
   :global iteratorS 0
   :local thisDate
   :local thisYear
   :local thisDay
   :local thisMonth
   :local thisLog
   :local logSeen
   :local logYear
   :local logDay
   :local logMonth
   :local expireMonth
   :set thisDate [/system clock get date]
   :set thisYear [:pick $thisDate 7 11]
   :set thisDay [:pick $thisDate 4 6]
   :set thisMonth [:pick $thisDate 0 3]
   :if ($thisMonth="jan") do { :set thisMonth "01"}
   :if ($thisMonth="feb") do { :set thisMonth "02"}
   :if ($thisMonth="mar") do { :set thisMonth "03"}
   :if ($thisMonth="apr") do { :set thisMonth "04"}
   :if ($thisMonth="may") do { :set thisMonth "05"}
   :if ($thisMonth="jun") do { :set thisMonth "06"}
   :if ($thisMonth="jul") do { :set thisMonth "07"}
   :if ($thisMonth="aug") do { :set thisMonth "08"}
   :if ($thisMonth="sep") do { :set thisMonth "09"}
   :if ($thisMonth="oct") do { :set thisMonth "10"}
   :if ($thisMonth="nov") do { :set thisMonth "11"}
   :if ($thisMonth="dec") do { :set thisMonth "12"}
   /tool user-manager session print without-paging
   :global counterS [/tool user-manager session print count-only]
   :foreach i in=[/tool user-manager session find] do { 
      :local logSeen [/tool user-manager session get $iteratorS till-time]
      :set logYear [:pick $logSeen 7 11]
      :set logDay [:pick $logSeen 4 6]
      :set logMonth [:pick $logSeen 0 3]
      :if ($logMonth="jan") do { :set logMonth "04";:set expireMonth "apr"}
      :if ($logMonth="feb") do { :set logMonth "05";:set expireMonth "may"}
      :if ($logMonth="mar") do { :set logMonth "06";:set expireMonth "jun"}
      :if ($logMonth="apr") do { :set logMonth "07";:set expireMonth "jul"}
      :if ($logMonth="may") do { :set logMonth "08";:set expireMonth "aug"}
      :if ($logMonth="jun") do { :set logMonth "09";:set expireMonth "sep"}
      :if ($logMonth="jul") do { :set logMonth "10";:set expireMonth "oct"}
      :if ($logMonth="aug") do { :set logMonth "11";:set expireMonth "nov"}
      :if ($logMonth="sep") do { :set logMonth "12";:set expireMonth "dec"}
      :if ($logMonth="oct") do { :set logMonth "01";:set expireMonth "jan";:set logYear ($logYear+1)}
      :if ($logMonth="nov") do { :set logMonth "02";:set expireMonth "feb";:set logYear ($logYear+1)}
      :if ($logMonth="dec") do { :set logMonth "03";:set expireMonth "mar";:set logYear ($logYear+1)} 
	  :set thisLog ($expireMonth ."/". $logDay . "/". $logYear)
      :if ($logYear>$thisYear) do {
      :put {"Kept session ".$iteratorS." which expires on ".$thisLog };
      :set keptS ($keptS+1) } else {
      :if ($logYear<$thisYear) do {
      /tool user-manager session remove $i; 
      :put {"Deleted session ".$iteratorS. " which expired on ".$thisLog};
      :set deletedS ($deletedS+1) } else {
      :if ($logMonth>$thisMonth) do {
      :put {"Kept session " .$iteratorS. " which expires on ".$thisLog};
      :set keptS ($keptS+1) }  else {
      :if ($logMonth<($thisMonth)) do {
      /tool user-manager session remove $i; 
      :put {"Deleted session ".$iteratorS. " which expired on ".$thisLog};
      :set deletedS ($deletedS+1) } else {
      :if ($logDay>=$thisDay) do {
      :put {"Kept session " .$iteratorS. " which expires on ".$thisLog};
      :set keptS ($keptS +1) }  else {
      /tool user-manager session remove $i; 
      :put {"Deleted session ".$iteratorS. " which expired on ".$thisLog};
      :set deletedS ($deletedS+1) }
      }
      }
      }
      }
	  :set iteratorS ($iteratorS+1);	  
      } 
   :put {"\n\n\r____________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t"}
   :put {"Records processed: \t" . $counterS}
   :put {"\n\rDeleted sessions: \t" . $deletedS}
   :put {"Kept sessions:\t\t" . $keptS}
   :put {"\n\r______________________________\n\r"}

   :log info ("\n\r_______________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t")
   :log info ("Records processed: \t" . $counterS)
   :log info ("\n\rDeleted sessions: \t" . $deletedS)
   :log info ("Kept sessions: \t\t" . $keptS)
   :log info ("\n\r_______________________________\n\r")

}


hello,

is it possible to delete logs and sessions older than 1 month instead of 3 months?
 
hsabrey
just joined
Posts: 21
Joined: Tue Jul 01, 2014 2:37 pm

Re: Solution: Automatically clean expired User-Manager accou

Sat Jan 31, 2015 9:59 pm

Hello guys,
In my case UM is used to generate and manage vouchers of 1hr per day, I want to automate the deletion of used vouchers.
I'm using UM 6.20 some locations have 6.22

Sorry I'm new to this point, and appreciate your support.
 
alfntoosh
just joined
Posts: 6
Joined: Wed May 21, 2014 2:59 am
Location: Yemen
Contact:

Re: Solution: Automatically clean expired User-Manager accounts

Sun Dec 20, 2015 9:30 am

after updated for work in new version 6.3.xx
# Date:       03/06/2011
# Revised:      22/02/2013
# Revised:      01/08/2013
# Revised:      20/12/2015 by Emad Alkadry #Yemen +967711505151
# Author:       Alfredo Agius
# Revised by Alexander Prozorov - adaptation for RouterOS version 6.xx
# File:         cleanUserManager
# Tested on:    RouterOS version 6.3.33 
#EM. AD.
# Description:    Deletes Mikrotik User-Manager accounts whos not active more or equal 1 month.
#            Accounts which are not yet activated are skipped.
#            Accounts which have valid profile are skipped.
#            A summary of all accounts skipped, deleted and kept is displayed in the end of the cycle to
#            console screen and to log.
#
# Notes:      
#            This script work if cloud update time updated
#            This script can be run either from WinBox or from console.
#            -- If console is used, all processing details will be shown, and a summary of operations in the end.
#            -- If WinBox is used, all processing details will be HIDDEN, and a summary of operations will be
#               sent to log.
#
# Use:         In Winbox, go to System > Script, create a new script, name it cleanUserManager and paste
#            this whole document in it. Click Apply and OK.
#
# Syntax:      To run the script, from terminal enter "/system script run cleanUserManager" without quotes.
if ([/ip cloud get status]="updated") do={
   :global iterator 0
   :global deleted 0
   :global skipped 0
   :global kept 0
   /tool user-manager user print brief  without-paging
   :global counter [/tool user-manager user print count-only]
   :do {
      :local thisDate
      :local thisYear
      :local thisDay
      :local thisMonth
      :local thisSeen
      :local thisProfile
      :local thisOwner
      :local thisCredit
      :local creditYear
      :local creditDay
      :local creditMonth
      :local expireMonth
      :local creditName
      :set $thisDate [/system clock get date]
      :set $thisYear [:pick $thisDate 7 11]
      :set $thisDay [:pick $thisDate 4 6]
      :set $thisMonth [:pick $thisDate 0 3]
      :if ($thisMonth="jan") do { :set thisMonth "01"}
      :if ($thisMonth="feb") do { :set thisMonth "02"}
      :if ($thisMonth="mar") do { :set thisMonth "03"}
      :if ($thisMonth="apr") do { :set thisMonth "04"}
      :if ($thisMonth="may") do { :set thisMonth "05"}
      :if ($thisMonth="jun") do { :set thisMonth "06"}
      :if ($thisMonth="jul") do { :set thisMonth "07"}
      :if ($thisMonth="aug") do { :set thisMonth "08"}
      :if ($thisMonth="sep") do { :set thisMonth "09"}
      :if ($thisMonth="oct") do { :set thisMonth "10"}
      :if ($thisMonth="nov") do { :set thisMonth "11"}
      :if ($thisMonth="dec") do { :set thisMonth "12"}
      :local thisSeen [/tool user-manager user get $iterator last-seen]
      :local thisProfile [/tool user-manager user get $iterator actual-profile]
:local thisOwner [/tool user-manager user get $iterator customer]
:set $creditName [/tool user-manager user get $iterator username]
      :if ([:len $thisProfile]!=0) do {
      :put {"Username ". $creditName . " Have valid profile:". $thisProfile . " Skipping ..."};
      :set $skipped ($skipped+1) } else {
      :if ([$thisSeen]!= "never") do {
      :set $creditYear [:pick $thisSeen 7 11]
      :set $creditDay [:pick $thisSeen 4 6]
      :set $creditMonth [:pick $thisSeen 0 3]
      :if ($creditMonth="jan") do { :set creditMonth "02";:set expireMonth "feb"}
      :if ($creditMonth="feb") do { :set creditMonth "03";:set expireMonth "mar"}
      :if ($creditMonth="mar") do { :set creditMonth "04";:set expireMonth "apr"}
      :if ($creditMonth="apr") do { :set creditMonth "05";:set expireMonth "may"}
      :if ($creditMonth="may") do { :set creditMonth "06";:set expireMonth "jun"}
      :if ($creditMonth="jun") do { :set creditMonth "07";:set expireMonth "jul"}
      :if ($creditMonth="jul") do { :set creditMonth "08";:set expireMonth "aug"}
      :if ($creditMonth="aug") do { :set creditMonth "09";:set expireMonth "sep"}
      :if ($creditMonth="sep") do { :set creditMonth "10";:set expireMonth "oct"}
      :if ($creditMonth="oct") do { :set creditMonth "11";:set expireMonth "nov"}
      :if ($creditMonth="nov") do { :set creditMonth "12";:set expireMonth "dec"}
      :if ($creditMonth="dec") do { :set creditMonth "01";:set expireMonth "jan";:set creditYear ($creditYear+1)} 
     :set $thisCredit ($expireMonth ."/". $creditDay . "/". $creditYear)
      :if ($creditYear>$thisYear) do {
      :put {"Kept username ".$creditName." which expires on ".$thisCredit };
      :set $kept ($kept+1) } else {
      :if ($creditYear<$thisYear) do {
      /tool user-manager user remove $creditName;
      :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
      :set $deleted ($deleted+1) } else {
      :if ($creditMonth>$thisMonth) do {
      :put {"Kept username " . $creditName . " which expires on " . $thisCredit};
      :set $kept ($kept+1) }  else {
      :if ($creditMonth<($thisMonth)) do {
      /tool user-manager user remove $creditName;
      :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
      :set $deleted ($deleted+1) } else {
       :if ($creditDay>=$thisDay) do {
       :put {"Kept username " . $creditName . " which expires on " . $thisCredit};
       :set $kept ($kept +1) }  else {
        /tool user-manager user remove $creditName;
       :put {"Deleted username ". $creditName . " which expired on " . $thisCredit};
       :set $deleted ($deleted+1) }
       }
       }
       }
       }
       }  else {
       :put {"Username ". $creditName . " is not yet activated. Skipping ..."};
       :set $skipped ($skipped+1)}
       }
       :set $iterator ($iterator+1)

       } while=($iterator!=$counter)
   :put {"\n\n\r________________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t"}
   :put {"Records processed: \t" . $counter}
   :put {"\n\rDeleted usernames: \t" . $deleted}
   :put {"Skipped usernames: \t" . $skipped}
   :put {"Kept usernames:\t\t" . $kept}
   :put {"\n\r__________________________________\n\r"}

   :log info ("\n\r_________________________________\n\n\rCleaning ready!\n\n\rPerformed these operations:\n\r\t")
   :log info ("Records processed: \t" . $counter)
   :log info ("\n\rDeleted usernames: \t" . $deleted)
   :log info ("Skipped usernames: \t" . $skipped)
   :log info ("Kept usernames: \t\t" . $kept)
   :log info ("\n\r_________________________________\n\r")

}

#END OF FILE
 
derr12
Member
Member
Posts: 411
Joined: Fri May 01, 2009 11:32 pm

Re: Solution: Automatically clean expired User-Manager accounts

Fri Jan 15, 2016 10:58 pm

Im on 6.33.3 and I ran this latest script. It doesnt seem to have any readout in the logs or terminal in winbox when executed. no errors or nothing.

How do i know if it's working or not?
 
alfntoosh
just joined
Posts: 6
Joined: Wed May 21, 2014 2:59 am
Location: Yemen
Contact:

Re: Solution: Automatically clean expired User-Manager accounts

Sun Mar 20, 2016 12:44 am

Im on 6.33.3 and I ran this latest script. It doesnt seem to have any readout in the logs or terminal in winbox when executed. no errors or nothing.

How do i know if it's working or not?
maybe you didn't have any users expired before 1 month
 
jhonnyp
just joined
Posts: 4
Joined: Wed May 19, 2010 4:46 pm

Re: Solution: Automatically clean expired User-Manager accounts

Fri Aug 12, 2016 3:37 pm

Thanks
Work Fine
V6.35.4
 
prawira
Trainer
Trainer
Posts: 357
Joined: Fri Feb 10, 2006 5:11 am

Re: Solution: Automatically clean expired User-Manager accounts

Fri Sep 16, 2016 11:44 am

i try the script on my RB433 with ROS 4.17 and it does not work.
the error is : input does not match any value of value-name

the script was tried from console and /system script and both give the same result.

any help will be appriciate

thank you

Paul
 
yerzhl
newbie
Posts: 39
Joined: Thu Sep 22, 2016 9:37 am

Re: Solution: Automatically clean expired User-Manager accounts

Sat Oct 29, 2016 1:59 pm

Hi alfagius,

Thanks for sharing the idea and solution. Really appreciate and helpful.
 
ronnel25
just joined
Posts: 2
Joined: Fri Sep 01, 2017 4:56 am

Re: Solution: Automatically clean expired User-Manager accounts

Tue Sep 05, 2017 3:46 pm

work fine @ 6.30.4

I have question how to delete the expire voucher after a day where can i edit the script
Thank in advance
 
mrdipesh1
just joined
Posts: 6
Joined: Fri Nov 03, 2017 5:50 am
Location: Nepal

Re: Solution: Automatically clean expired User-Manager accounts

Fri Nov 03, 2017 6:10 am

trigger
:delay 60
/system script run delete_expired
Here the trigger script waits for 60 second then calls the delete_expired script
delete_expired
:foreach i in [/ip hotspot user find] do={
:if ([/ip hotspot user get $i limit-uptime]<=[/ip hotspot user get $i uptime]) do={
/ip hotspot user remove $i;
}
}
/system script run trigger
Here delete_expired scripts checks all the users whose limit-uptime is equal or less to uptime.
If any user is found expired then it will delete them.
And after If() statement is completed it will again call trigger script. And this loop goes continuously.

To check if this code work for you or not, just simply create a test user with no limit-uptime set and run this script
or you can add a log to check
:log info "your message"
whether the script is working every seconds or not.

It works for me
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 209
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: Solution: Automatically clean expired User-Manager accounts

Sun Nov 26, 2017 8:49 pm

Try this Script
/tool user-manager user remove numbers=[find where !actual-profile];
 
Echniajaw
just joined
Posts: 3
Joined: Wed Jul 11, 2018 7:14 pm

Re: Solution: Automatically clean expired User-Manager accounts

Sun Sep 16, 2018 2:06 am

hi

i need same kind of this usefull script but instend of removing expired User remove the users that reached total bytes limit because in my services im not using period to limit im using how much user using data as download and upload if anybody can help will be great

thanks in advance
 
kmznet
just joined
Posts: 8
Joined: Thu Sep 12, 2019 11:47 am

Re: Solution: Automatically clean expired User-Manager accounts

Tue Sep 24, 2019 9:29 am

With UM latest version, it is easy to accomplish:
Look for [Users]
[Total time left] [is] [equal to] type 0 (zero)
and click Search... voila. There the expired users list that you can remove from the menu bar command.
Image
 
freemannnn
Forum Veteran
Forum Veteran
Posts: 700
Joined: Sun Oct 13, 2013 7:29 pm

Re: Solution: Automatically clean expired User-Manager accounts

Tue Sep 24, 2019 10:35 am

With UM latest version, it is easy to accomplish:
Look for [Users]
[Total time left] [is] [equal to] type 0 (zero)
and click Search... voila. There the expired users list that you can remove from the menu bar command.
the is not [Total time left] just [Time Left]
 
alfagius
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Mon Feb 21, 2011 4:07 pm

Re: Solution: Automatically clean expired User-Manager accounts

Tue Mar 02, 2021 6:50 pm

Glad to see people are still finding it useful and still tinker with it after all these years :D

I changed job and don't tinker with MikroTiks anymore, which is a pity. I miss the little buggers.

Who is online

Users browsing this forum: No registered users and 27 guests