Community discussions

MikroTik App
 
eles
just joined
Topic Author
Posts: 14
Joined: Tue Jun 18, 2013 6:20 pm

dhcp-server lease find where host-name (contains|in) [stuff] doesn't return anything?

Fri May 28, 2021 2:59 pm

How can I search in the leases list if I want to find a host-name that contains something?


But also, on the command line even,

/ip dhcp-server lease print where host-name = "something" ;; spits an error on "="
/ip dhcp-server lease print where host-name is "something" ;; no error but no result, and 'is' is colored red
/ip dhcp-server lease print where host-name in "something" ;; no error and 'in' is colored yellow, but the result still is empty.
/ip dhcp-server lease get [find where host-name in "something"] ;; 'in' colored yellow, but the answer is 'no such item'.

What am I missing?
(also need this to work in the on-lease script).

(ROS 6.47.9)
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: dhcp-server lease find where host-name (contains|in) [stuff] doesn't return anything?

Fri May 28, 2021 5:01 pm

print is not the right way to do it, you need to use find and get.

Eks
/ip dhcp-server lease find where host-name="Chromecast"
Will find all with name "Chromecast"

To get some output, you need to use put
:put [/ip dhcp-server lease find where host-name="Chromecast"]
This will get all ID, so you then need to put it in a foreach loop
{
:foreach i in=[/ip dhcp-server lease find where host-name="Chromecast"] do {
	:put [/ip dhcp-server lease get $i]

}
}
All in one line:
/ip dhcp-server lease;:foreach i in=[find where host-name="Chromecast"] do={:put [get $i]}
 
eles
just joined
Topic Author
Posts: 14
Joined: Tue Jun 18, 2013 6:20 pm

Re: dhcp-server lease find where host-name (contains|in) [stuff] doesn't return anything?

Fri May 28, 2021 5:29 pm

Thanks, this finds and prints all that the host-name is _exact_; But what if I want it to 'contain' the part string? it is possible on Winbox... (ok I know this may mean nothing but still.)

(tried
/ip dhcp-server lease;:foreach i in=[find where host-name in "part i want to find"] do={:put [get $i]}
/ip dhcp-server lease;:foreach i in=[find where "part i want to find" in host-name] do={:put [get $i]}
no results?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: dhcp-server lease find where host-name (contains|in) [stuff] doesn't return anything?

Fri May 28, 2021 6:45 pm

/ip dhcp-server lease print where host-name = "something" ;; spits an error on "="
/ip dhcp-server lease print where host-name is "something" ;; no error but no result, and 'is' is colored red
/ip dhcp-server lease print where host-name in "something" ;; no error and 'in' is colored yellow, but the result still is empty.
/ip dhcp-server lease get [find where host-name in "something"] ;; 'in' colored yellow, but the answer is 'no such item'.
really you try "random" commands?
 
eles
just joined
Topic Author
Posts: 14
Joined: Tue Jun 18, 2013 6:20 pm

Re: dhcp-server lease find where host-name (contains|in) [stuff] doesn't return anything?

Fri May 28, 2021 7:00 pm

really you try "random" commands?
not on 'production' equipment :) but yes ? Also it's not 'random' if I'm trying get it to do _something_ :)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: dhcp-server lease find where host-name (contains|in) [stuff] doesn't return anything?

Fri May 28, 2021 7:05 pm

really you try "random" commands?
not on 'production' equipment :) but yes ? Also it's not 'random' if I'm trying get it to do _something_ :)
one moment, please....
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: dhcp-server lease find where host-name (contains|in) [stuff] doesn't return anything?

Fri May 28, 2021 7:08 pm

on terminal:

all is case-sensitive

exact host name;
/ip dhcp-server lease print where host-name="whaiIwant"

different host name;
/ip dhcp-server lease print where host-name!="whaiIwant"

partial / regexp hostname with partial
/ip dhcp-server lease print where host-name~"DESKTOP"
(for ex. DESKTOP-48UDNGH, DESKTOP-ICQPPS7, etc.)

partial / regexp hostname with regexp
/ip dhcp-server lease print where host-name~"PC-0.."
(for ex. PC-001, PC-002, PC-0XS, etc.)

partial / regexp hostname with NOT partial
/ip dhcp-server lease print where !(host-name~"DESKTOP")

partial / regexp hostname with NOT regexp
/ip dhcp-server lease print where !(host-name~"PC-0..")
Last edited by rextended on Fri May 28, 2021 7:27 pm, edited 2 times in total.
 
eles
just joined
Topic Author
Posts: 14
Joined: Tue Jun 18, 2013 6:20 pm

Re: dhcp-server lease find where host-name (contains|in) [stuff] doesn't return anything?  [SOLVED]

Fri May 28, 2021 7:13 pm

FOUND IT!

/ip dhcp-server lease;:foreach i in=[find where host-name~"part i want to find"] do={:put [get $i]}

so it's the ~ operator according to wiki:
“~” binary operator that matches value against POSIX extended regular expression
Sorry for the noise :)
 
eles
just joined
Topic Author
Posts: 14
Joined: Tue Jun 18, 2013 6:20 pm

Re: dhcp-server lease find where host-name (contains|in) [stuff] doesn't return anything?

Fri May 28, 2021 7:20 pm


partial / regexp hostname with partial
/ip dhcp-server lease print where host-name~"DESKTOP"
(for ex. DESKTOP-48UDNGH, DESKTOP-ICQPPS7, etc.)

partial / regexp hostname with regexp
/ip dhcp-server lease print where host-name~"PC-0.."
(for ex. PC-001, PC-002, PC-0XS, etc.)

partial / regexp hostname with NOT partial
/ip dhcp-server lease print where !(host-name~"DESKTOP")

partial / regexp hostname with NOT regexp
/ip dhcp-server lease print where !(host-name~"PC-0..")
(for ex. PC-001, PC-002, PC-0XS, etc.)
This, thank you too I found in the wiki at the same time as you've posted the answer :) thank you for sharing :)

Who is online

Users browsing this forum: marcelofares, Speedyboat13 and 25 guests