I set a hotspot server on my 2011 router board v6.35.2 and in the user profile scripts, I create this script On Login:
:local date [ /system clock get date ]
:if ([/ip hotspot user find where name=$“mac-address”] = “” ) do={
:log warning (“The user “.$“mac-address”.” does not exist”)
/ip hotspot user add mac-address=$“mac-address” name=$“mac-address” comment=$date limit-uptime=“00:00:01”;
} else={
:log warning (“The user “.$“mac-address”.” exist”)
}
When the first device log on hotspot, the script does not find that device MAC and create a static user
The problem happens when next devices log on. The script “find” all that MAC adresses in the user table, and do not create a static user.
How it can be possible? whats is wrong with the script?
The issue seems to be that $"mac-address" is a system variable, and system variable can act VERY odd.
If you put it into a local variable right away it seems to work much better.
Try this:
/ip hotspot user {
:local macA $"mac-address"
:local dateToday [/system clock get date]
:put $macA
:if ([:len [find name=$macA]] = 0) do={
:log warning ("The user " . $macA . " does not exist")
add mac-address=$macA name=$macA comment=$dateToday limit-uptime="00:00:01"
} else={
:log warning ("The user " . $macA . " exist")
}
}
I only tested this in the terminal, so not sure how it will work in a live system.
I also cleaned up the code a little bit.