Problem with Script On Login

Dear friends

Sorry for bad english

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?

Thanks for everybody

I hope everybody understand what I try explain. If do not, please ask me

Dear friends. I relly need some help.

Tanks

Hey Bud

Just noticed a problem with one of my scripts, and decided to have a look around here. I Had your issue for a while.

TBH - i cannot exactly say how i got around it - i think that open :if statements helped (couldn’t get an else to work myself)

See if any of the info here can help

http://forum.mikrotik.com/t/hotspot-data-limits/90475/1

Good Luck

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.