Community discussions

MikroTik App
 
gammy69er
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 79
Joined: Sun May 18, 2014 3:01 am

Find this OR that.

Mon Feb 12, 2024 2:58 am

Having real trouple searching this one up.. as the search terms are 2 letters or operators that aren't accepted by the Forum.

Trying to write a script that does a Find for <value> OR <value>. In this instance, trying to use the same variable, just with different values.

test script is
[/foreach count in=[/interface find name!=ether5] do={:put [/interface get value-name=name number=$count] }]
This produces an output where it finds all interfaces and outputs them in terminal, unless it is named ether5.
[/foreach count in=[/interface find name!=ether5 name~"(ether|sfp|combo)"] do={:put [/interface get value-name=name number=$count] }] 
This one produces similar output, but instead of printing all interfaces, only prints ones with names similar to ether, sfp or combo (general ethernet interfaces in Mikrotik).

The problem I have is that I want to have multiple "name!=ether5" entires, but at this time have to have multiple entires. I would have expected "&&" (and) and "||" (or) to work with the operation, but cannot get the desired output. Usually it results in the "not" variable failing.

e.g of code that works...
[/foreach count in=[/interface find name!=ether5 name!=ether2 name~"(ether|sfp|combo)"] do={:put [/interface get value-name=name number=$count] }]
This does as required - but having multiple <variable>!=<value> is really Yuck.

e.g of what I would expect to work
[/foreach count in=[/interface find name!="ether5"||"ether2" name~"(ether|sfp|combo)"] do={:put [/interface get value-name=name number=$count] }]
or
[/foreach count in=[/interface find name!="(ether5|ether2)" name~"(ether|sfp|combo)"] do={:put [/interface get value-name=name number=$count] }]
So, My question is if there is any way to "or" a "find" command, without having to fully script out the <variable>!=<value> multiple times per line. Trying to get it to a point where I can potentially array a script using similar code.

As you can well see here - the
name~"(ether|sfp|combo)"
is already a type of "or" for this - but just cannot get anything similar for "not"
 
trkk
just joined
Posts: 17
Joined: Tue Mar 08, 2022 1:36 pm
Location: +09:00

Re: Find this OR that.

Mon Feb 12, 2024 11:16 am

These should work.
> [/foreach count in=[/interface find name~"(ether|sfp|combo)" !(name~"(ether5|ether2)")] do={:put [/interface get value-name=name number=$count]}]
or
> [/foreach count in=[/interface find where !(name~"(ether5|ether2)") name~"(ether|sfp|combo)"] do={:put [/interface get value-name=name number=$count]}]
And
name~"^(ether|sfp|combo)" !(name~"^(ether5|ether2)")
may be better in this case. (add '^' to front of regex patterns)

Who is online

Users browsing this forum: No registered users and 8 guests