Community discussions

MikroTik App
 
jaxed7
newbie
Topic Author
Posts: 32
Joined: Wed May 17, 2023 11:15 pm

Script to remove unflaged sessions

Sun May 28, 2023 5:21 pm

Hey all
I want to remove nonactive session in /user-manager session and I got this code so far but it's not working and I don't know how to get it right.
:local Flag
:set Flag [/user-manager session find where flags=""]
:user-manager session print where flags=""
:if([:len $Flag] > 0) do={/user-manager session remove $Flag}
Last edited by jaxed7 on Sun May 28, 2023 7:13 pm, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script to remove unflaged sessions

Sun May 28, 2023 6:55 pm

[…] and I got his code […]
From who, from the junk shop?


Posting random and useless code diverts attention from the underlying problem.
Ask what you want to do, don't ask to change a code that doesn't work (?) to do what you want to do...
 
jaxed7
newbie
Topic Author
Posts: 32
Joined: Wed May 17, 2023 11:15 pm

Re: Script to remove unflaged sessions

Sun May 28, 2023 7:13 pm

[…] and I got his code […]
From who, from the junk shop?
Sorry that was a typo (I asked and ChatGPT generated that)

I'm looking for a script that can remove inactive sessions from the '/user-manager session' log. With each user login and logout, a log is created, and after a few days, it can grow to hundreds of thousands of entries. I want the script to run periodically, say every 24 hours, to remove the inactive entries. However, I don't want to remove all entries at once, as that would cause users to lose their connection and have to reconnect again hence the script should only remove entries without A (active) flag. How can I achieve this?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script to remove unflaged sessions  [SOLVED]

Sun May 28, 2023 7:51 pm

I do not have a user-manager v7 to test now, at home, but probably are like the v6, only one instruction:
/user-manager session remove [find where active=no]

If do not work, ask it and I test tomorrow at work with the test device.
 
jaxed7
newbie
Topic Author
Posts: 32
Joined: Wed May 17, 2023 11:15 pm

Re: Script to remove unflaged sessions

Mon May 29, 2023 5:39 pm

That worked man thanks a bunch.

Who is online

Users browsing this forum: almdandi and 21 guests