Community discussions

MikroTik App
 
unridaz
newbie
Topic Author
Posts: 34
Joined: Tue Mar 19, 2013 11:48 pm

How to use [:nothing]?

Tue Aug 04, 2015 6:43 pm

Hello,

I am trying to do a check on DHCP-CLIENT like so:

:if ([/ip dhcp-client get [find interface=ether3] gateway != [:nothing]) do={:put "hi";} else={:put "bye"};

However, when ether 3 has a gateway and when ether3 does not have a gateway the result is the same. Instead of [:nothing], I also tried " " and that didn't work either..

I'm trying to determine if ether3 has a gateway or not and do something based on the result...


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

Re: How to use [:nothing]?

Tue Aug 04, 2015 6:52 pm

In recent RouterOS versions, you can use the "any" operator to check if a property is set (i.e. has a value, rather than "nothing") as part of "where" expressions in "find" or "print".

Since you want to check a particular item, I suggest a print with "count-only" and an appropriate expression.

So f.e.
:if ([/ip dhcp-client print count-only where interface=ether3 && any gateway] != 0) do={:put "hi";} else={:put "bye"};