When creating the scheduler, in the On Event part, which is the last field, we must indicate through commands the elimination of hotspot users and in the interval field indicate that it will be executed 1d 00:00:00
You can also use the MikroTik Scheduler together with scripts. The Scheduler allows you to run scripts at specific times or at regular intervals.
Step 1: Create a Script to Delete Expired Users
First, you will need to create a script in MikroTik that identifies and removes Hotspot users whose credentials have expired.
- Access your MikroTik device using WinBox, WebFig, or SSH.
- Go to System → Scripts and click the plus sign (+) to add a new script.
- Give the script a nameEg
RemoveExpiredHotspotUsers
. - In the countryside Source, enter the script that will check and remove expired users. A basic script example would be:
:foreach i in=[/ip hotspot user find where uptime>1d] do={
/ip hotspot user remove $i
}
This script iterates through all Hotspot users and removes those whose connection time (uptime
) has exceeded 24 hours (1 day). Adjust the condition where uptime>1d
as needed, depending on how you want to handle the expiration.
Step 2: Configure the Scheduler to Run the Script
After creating the script, you will need to configure the Scheduler to run this script automatically at regular intervals.
- Go to System → Scheduler and click the plus sign (+) to create a new task.
- Give the task a nameEg
DailyUserCleanup
. - In the countryside On Event, enter the name of the script you created preceded by
/system script run
. For example: uterine
/system script run RemoveExpiredHotspotUsers
- Set the interval of time in which you want this script to run. To run it daily, you can set the field Start Time at the desired time and the field Interval a
1d
to run every 24 hours. - Click OK to save the scheduled task.
Additional considerations
- Testing: Before putting this into production, it's a good idea to test the script manually to make sure it works as you expect and doesn't affect non-expired users.
- Customization: Depending on your specific needs, you may want to modify the script to fit different expiration criteria, such as based on the time since the user was created (
limit-uptime
) instead ofuptime
figure. - Cautious Use: Please note that this script will delete users based on the specified criteria without additional confirmation, so it is important to ensure that the criteria are correct to avoid deleting unintended users.
Using the Scheduler and scripts in MikroTik offers a flexible and powerful solution for managing Hotspot users and other automated tasks, ensuring your network stays organized and functional according to your operational needs.
There are no tags for this post.