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}
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…
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?
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.
add interval=24h name=userman-cleanup on-event="/system script run userman-cleanup" \
start-date=jan/01/2024 start-time=02:00:00_
This script does the following:
Creates a function cleanupLog that:
o Gets current time and date for logging purposes
o Logs the start of the cleanup process
o Counts removed sessions
o Finds and removes all inactive sessions
o Logs completion with the number of sessions removed
Uses the RouterOS v7 user-manager commands to safely remove only inactive sessions
Includes detailed logging for monitoring and troubleshooting
Preserves all active sessions (those with the A flag)
To implement this:
Create a new system script:
/system script add name=userman-cleanup source=
Add it to the scheduler to run every 24 hours (suggested at 2 AM):
/system scheduler add interval=24h name=userman-cleanup on-event="/system script run userman-cleanup" start-date=jan/01/2024 start-time=02:00:00
You can also run it manually to test:
/system script run userman-cleanup