Community discussions

MikroTik App
 
User avatar
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3300
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Bug in script variables?

Fri Jun 21, 2019 3:43 pm

I do not get the desired result from my script so have done some testing.

It seems that the variables files when there are two - (minus) in the string.

This is from my DHCP server with name "DHCP-Pool-vlan1-Home"
I would like to get the number of leases in the DHCP server, but it seems to feil due to the pool name

Running this from cli, I should get 95 for all test.
[
:local orig "DHCP-Pool-vlan1-Home"
:local test1 "vlan1-Home"
:local test2 "-vlan1-Home"
:local test3 "l-vlan1-Home"
:local test4 "l-vlan1-H"
:local test5 "vlan1-H"
:put "orig=$([:len [/ip dhcp-server lease find where server~"$orig"]])"
:put "test1=$([:len [/ip dhcp-server lease find where server~$test1]])"
:put "test2=$([:len [/ip dhcp-server lease find where server~"$test2"]])"
:put "test3=$([:len [/ip dhcp-server lease find where server~"$test3"]])"
:put "test4=$([:len [/ip dhcp-server lease find where server~"$test4"]])"
:put "test5=$([:len [/ip dhcp-server lease find where server~"$test5"]])"
]
orig=0
test1=95
test2=95
test3=0
test4=0
test5=95
Anyone has an idea of what is going on? Bug?
 
User avatar
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3300
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Bug in script variables?

Fri Jun 21, 2019 4:21 pm

Not sure what is going on???

Renamed on pool to poolguest

Works
:put [/ip dhcp-server lease find where server~"uest"]
*1703;*1704;*1707;*1709;*170a;*170b;*170c;*170d
Does not work
:put [/ip dhcp-server lease find where server~"guest"]
Works
/ip dhcp-server lease print where server~"est"
Flags: X - disabled, R - radius, D - dynamic, B - blocked
 #   ADDRESS                                        MAC-ADDRESS       HOST-NAME       SERVER       RATE-LIMIT       STATUS
 0   ;;; jun/01/2019 13:08:56
     10.10.20.191                                   00:1D:xC:06:1D:F5                 DHCP-vlan...                  bound
 1   ;;; jun/01/2019 13:12:51
     10.10.20.190                                   E4:A4:x1:04:7F:8B HE16        DHCP-vlan...                  waiting
 2   ;;; jun/07/2019 17:44:56
     10.10.20.189                                   C0:E8:x2:22:46:31 iPhone          DHCP-vlan...                  bound
.....
Does not work
/ip dhcp-server lease print where server~"gu"

From manual
https://wiki.mikrotik.com/wiki/Manual:Scripting

~
binary operator that matches value against POSIX extended regular expression

Print all routes which gateway ends with 202
/ip route print where gateway~"^[0-9 \\.]*202\$"


And this should work? (but does not)
 /ip dhcp-server lease print where server="poolguest"
Last edited by Jotne on Fri Jun 21, 2019 4:31 pm, edited 1 time in total.
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1782
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

Re: Bug in script variables?

Fri Jun 21, 2019 4:24 pm

this has to be a bug
 
krisjanisj
Member Candidate
Member Candidate
Posts: 101
Joined: Wed Feb 20, 2019 2:53 pm
Contact:

Re: Bug in script variables?

Fri Jun 21, 2019 4:27 pm

3 things:
1) /ip pool =/= Server under dhcp-server lease (You keep using "/ip dhcp-server lease find where server" in Your script - clarify on what exactly You are changing: dhcp-server name or /ip pool name)
2) Keep 1 line empty above [ code ] block so it formats properly (I keep formating Your posts recently just so it properly formats into a nice code-box).
3) What version are You testing with?
 
User avatar
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3300
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Bug in script variables?

Fri Jun 21, 2019 4:34 pm

1)

Since this is a part of the pool script does does not list static list, it's start under /ip pool
But I should be able to use /ip dhcp-server lease even in /ip pool as long as I do use full url.

Does not work
ip dhcp-server> /ip dhcp-server lease print where server~"gu"
Flags: X - disabled, R - radius, D - dynamic, B - blocked
 #   ADDRESS                                        MAC-ADDRESS       HOST-NAME       SERVER       RATE-LIMIT       STATUS
NB running 6.43.4


more test
[admin@r1] /ip dhcp-server> lease  print where server~"gu"
Flags: X - disabled, R - radius, D - dynamic, B - blocked
 #   ADDRESS                                        MAC-ADDRESS       HOST-NAME       SERVER       RATE-LIMIT       STATUS
[admin@r1] /ip dhcp-server> lease  print where server~"est"
Flags: X - disabled, R - radius, D - dynamic, B - blocked
 #   ADDRESS                                        MAC-ADDRESS       HOST-NAME       SERVER       RATE-LIMIT       STATUS
 0   ;;; jun/01/2019 13:08:56
     10.10.20.191                                   00:1D:EC:06:1D:F5                 DHCP-vlan...                  bound
 1   ;;; jun/01/2019 13:12:51
     10.10.20.190                                   E4:A4:71:04:7F:8B HE16        DHCP-vlan...                  waiting
 2   ;;; jun/07/2019 17:44:56
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7056
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Bug in script variables?

Fri Jun 21, 2019 4:40 pm

Problem looks to be specific to your router:


[admin@3C22-atombumba] > /ip dhcp-server lease print count-only where server~"DHCP-Pool-vlan1-Home"
18
[admin@3C22-atombumba] > /ip dhcp-server lease print count-only where server~"vlan1-Home"
18
[admin@3C22-atombumba] > /ip dhcp-server lease print count-only where server~"-vlan1-Home"
18
[admin@3C22-atombumba] > /ip dhcp-server lease print count-only where server~"l-vlan1-Home"
18
[admin@3C22-atombumba] > /ip dhcp-server lease print count-only where server~"l-vlan1-H"
18
[admin@3C22-atombumba] > /ip dhcp-server lease print count-only where server~"vlan1-H"
18
 
User avatar
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3300
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Bug in script variables?

Fri Jun 21, 2019 4:49 pm

What os are you on, I am on 6.43.4
 
User avatar
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3300
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Bug in script variables?

Fri Jun 21, 2019 5:21 pm

Error found Blush....

I did mix pool name with dhcp-server name....
UFF, sorry....

Who is online

Users browsing this forum: raiser and 70 guests