Community discussions

MikroTik App
 
lukkes
Member Candidate
Member Candidate
Topic Author
Posts: 177
Joined: Mon Jun 16, 2008 2:12 am
Location: Venezuela
Contact:

find with logic AND

Tue Apr 21, 2015 5:57 pm

Hello people, i have a list of dhcp-client interfaces

wan1 bound comment balanced
wan2 bound comment balanced
wan3 bound comment balanced
wan4 bound comment balanced
wan5 bound comment balanced
wan6 bound comment balanced
wan7 bound comment admin

there is a way to ([find status = "bound"] and comment~"balanced")in the same statement?

i need to get the name of the interface that meet the two conditions

thanks
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: find with logic AND

Tue Apr 21, 2015 6:58 pm

Yes. And it is quite literally using the word "and", i.e.
[find status = "bound" and comment~"balanced"]
You can also use the "&&" as an equivalent to "and", if you're more accustomed to that from programming languages.
 
lukkes
Member Candidate
Member Candidate
Topic Author
Posts: 177
Joined: Mon Jun 16, 2008 2:12 am
Location: Venezuela
Contact:

Re: find with logic AND

Tue Apr 21, 2015 7:15 pm

this is so shameful for me, i hace experience in some programming languages, routers included, and when i post some question it's because i've tried everything, last night i try a lot of times this
:foreach iface in=[/ip dhcp-client find comment~"balance" && status="bound"] do={ 
   :set ifname ([/ip dhcp-client get $iface interface]);
   :log info $ifname;
};
but doesn't work, but now it works normal, maybe i was so tired and have some typo error, thanks a lot.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: find with logic AND

Tue Apr 21, 2015 7:33 pm

If you're trying to get stuff out of those matches (as opposed to, let's say, remove all of them), it's more efficient to use "print as-value", e.g.
:foreach iface in=[/ip dhcp-client print as-value where comment~"balance" && status="bound"] do={ 
   :log info ($iface->"interface");
};
 
lukkes
Member Candidate
Member Candidate
Topic Author
Posts: 177
Joined: Mon Jun 16, 2008 2:12 am
Location: Venezuela
Contact:

Re: find with logic AND

Tue Apr 21, 2015 8:54 pm

ok bro, i will try that, thanks a lot.

Who is online

Users browsing this forum: rextended and 38 guests