fbpx

How can I use the MikroTik scheduler to automatically delete hotspot users so that, for example, they expire in 24 hours?

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.

  1. Access your MikroTik device using WinBox, WebFig, or SSH.
  2. Go to System → Scripts and click the plus sign (+) to add a new script.
  3. Give the script a nameEg RemoveExpiredHotspotUsers.
  4. 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.

  1. Go to System → Scheduler and click the plus sign (+) to create a new task.
  2. Give the task a nameEg DailyUserCleanup.
  3. 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
  1. 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.
  2. 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 of uptime 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.
Did this content help you?
Facebook
Twitter
LinkedIn
WhatsApp
Telegram

Other documents in this category

Leave your comment

Your email address will not be published. Required fields are marked with *

Tutorials available at MikroLABs

No Courses Found!

DISCOUNT CODE

AN24-LIB

applies to MikroTik books and book packs

Days
Hours
Minutes
Seconds

Introduction to
OSPF - BGP - MPLS

Sign up for this Free course

MAE-RAV-ROS-240118
Days
Hours
Minutes
Seconds

Sign up for this Free course

MAS-ROS-240111

Promo for Three Kings Day!

KINGS24

15%

all the products

MikroTik courses
Academy courses
MikroTik books

Take advantage of the Three Kings Day discount code!

* promotion valid until Sunday January 7, 2024
** the code (KINGS24) applies to shopping cart
*** buy your course now and take it until March 31, 2024

New Year's Eve Promo!

NY24

20%

all the products

MikroTik courses
Academy courses
MikroTik books

Take advantage of the New Year's Eve discount code!

* promotion valid until Monday, January 1, 2024
** the code (NY24) applies to shopping cart
*** buy your course now and take it until March 31, 2024

Christmas discounts!

XMAS23

30%

all the products

MikroTik courses
Academy courses
MikroTik books

Take advantage of the discount code for Christmas!!!

**codes are applied in the shopping cart
Promo valid until Monday December 25, 2023

CYBER WEEK DISCOUNTS

CW23-MK

17%

all MikroTik OnLine courses

CW23-AX

30%

all Academy courses

CW23-LIB

25%

all MikroTik Books and Book Packs

Take advantage of the discount codes for Cyber ​​Week!!!

**codes are applied in the shopping cart
Promo valid until Sunday December 3, 2023

BLACK FRIDAY DISCOUNTS

BF23-MX

22%

all MikroTik OnLine courses

BF23-AX

35%

all Academy courses

BF23-LIB

30%

all MikroTik Books and Book Packs

Take advantage of the discount codes for Black Friday!!!

**Codes are applied in the shopping cart

codes are applied in the shopping cart
valid until Sunday November 26, 2023

Days
Hours
Minutes
Seconds

Sign up for this Free course

MAE-VPN-SET-231115

Halloween promo

Take advantage of discount codes for Halloween.

Codes are applied in the shopping cart

HW23-MK

11% discount on all MikroTik OnLine courses

11%

HW23-AX

30% discount on all Academy courses

30%

HW23-LIB

25% discount on all MikroTik Books and Book Packs

25%

Register and participate in the free course Introduction to Advanced Routing with MikroTik (MAE-RAV-ROS)

Today (Wednesday) October 11, 2023
7pm to 11pm (Colombia, Ecuador, Peru)

MAE-RAV-ROS-231011