Community discussions

MUM Europe 2020
 
User avatar
diodo
just joined
Topic Author
Posts: 8
Joined: Fri May 06, 2016 3:58 am
Contact:

Problem with Script On Login

Thu Jul 14, 2016 5:10 am

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
 
User avatar
diodo
just joined
Topic Author
Posts: 8
Joined: Fri May 06, 2016 3:58 am
Contact:

Re: Problem with Script On Login

Thu Jul 14, 2016 5:12 am

I hope everybody understand what I try explain. If do not, please ask me
 
User avatar
diodo
just joined
Topic Author
Posts: 8
Joined: Fri May 06, 2016 3:58 am
Contact:

Re: Problem with Script On Login

Thu Jul 14, 2016 3:48 pm

Dear friends. I relly need some help.

Tanks
 
gammy69er
newbie
Posts: 46
Joined: Sun May 18, 2014 3:01 am

Re: Problem with Script On Login

Fri Jul 22, 2016 10:31 am

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/viewtopic.php?f=9&t=99515

Good Luck
 
User avatar
Deantwo
Member
Member
Posts: 310
Joined: Tue Sep 30, 2014 4:07 pm

Re: Problem with Script On Login

Thu Jul 28, 2016 3:28 pm

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.
I wish my FTP was FTL.

Who is online

Users browsing this forum: MSN [Bot] and 8 guests