Steps:
1 - Create User Profile In /ip hotspot user profiles - here its "Monthly", change as needed
- No Session Timeout or Keepalive Timeout in User Profile
2 - Set SMTP settings in /Tools Email
3 - Add User + Add Schedule with On Event script (copy and paste for each user or automate with Excel)
Add User will:
(a) add user with profile "Monthly"
(b) add profile name and expiry date as comment="Monthly - Expire on $expiryDate"
- No Limit Uptime needed in User
Scheduler will:
(a) Send email notification to admin, for this set SMTP in /Tools Email
(b) Disable User so they can't login again
(c) Disable Scheduler for the user
(d) Remove Lease in case user is logged in
4 - Renew Expired User, will enable disabled user and scheduler and set new expiry date and time in schedule
5 - Remove User, will remove user and schedule (Optional)
Copy and Paste Step 3 (creation), 4 (Renew) or 5 (Remove User) as needed (Manually create Step 1 and 2 one time only at the beginning of the setup)
Step 1 - Create User Profile called "Monthly" in /ip hotspot user profiles - change User Profile name as needed and also change in script
Step 2 - Set SMTP settings in /Tools Email
Step 3 - Add User and Schedule - do this for every user or automate batch addition using Excel:
Set variables to be user in script (you only need to set these, nothing else needs change)
:global userName "User";
:global expiryDate "Mar/1/2020";
:global expiryTime "03:00:00";
Add Schedule with On Event Script
/system scheduler add interval=0 name=$userName on-event="/ip h u d [/ip h u f name="$userName"]; /system scheduler disable [find name=$userName]; /ip dhcp-server lease remove [find mac-address=[/ip hotspot active get [find user=$userName] mac-address]]; /tool e-mail send to=email@gmail.com subject="Wifi $userName Expired on $expiryDate at $expiryTime" body="" start-tls=yes;" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=$expiryDate start-time=$expiryTime;
Add User
/ip hotspot user add name=$userName password=common profile=Monthly limit-uptime=00:00:00 server=all comment="Monthly - Expire on $expiryDate";
Step 4 - Renew Expired User (when needed)
:global userName "User";
:global expiryDate "Mar/1/2020";
:global expiryTime "03:00:00";
Renew Schedule Event Script
/system scheduler set [find name=$userName] interval=0 name=$userName on-event="/ip h u d [/ip h u f name="$userName"]; /system scheduler disable [find name=$userName]; /ip dhcp-server lease remove [find mac-address=[/ip hotspot active get [find user=$userName] mac-address]]; /tool e-mail send to=email@gmail.com subject="Wifi $userName Expired on $expiryDate at $expiryTime" body="" start-tls=yes;" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=$expiryDate start-time=$expiryTime;
Enable User and Schedule if Disabled
/ip hotspot user enable [find name=$userName];
/ip hotspot user set comment="Monthly - Expire on $expiryDate" [find name=$userName];
/system scheduler enable [find name=$userName];
Step 5 - Remove User (when needed)
:global userName "User";
/system scheduler remove $userName;
/ip hotspot user remove $userName;
I hope that is useful,
you can also add remove Schedule and User automatically but there is no need as you can Renew the User with Step 4.