Community discussions

MikroTik App
 
AquaL1te
newbie
Topic Author
Posts: 32
Joined: Mon Sep 16, 2019 9:05 am

Create list of interfaces in a loop

Sat May 16, 2020 4:36 pm

I want to do: `/interface bridge port set [find interface="ether1,ether2,ether3,ether4,ether5,sfp1" name=br0] pvid=10`

But I noticed that the find command has to match exactly. so `find interface="ether1"` will work, as for ether2. But that's a manual loop. So then I wanted to loop over all interfaces and then do the command to set the PVID to 10. I want to do this, because 10 is my native VLAN (/interface bridge vlan add bridge=br0 untagged=ether1,ether2,ether3,ether4,ether5,sfp1 vlan-ids=10). I don't want to use VLAN 1, because I remember something that this VLAN may have security risks. However, I can't find any direct answer for this. So if someone have some comments on that, that would be great. It could also be some legacy stuff or just Cisco specific.

But back to scripting. Is there a way to loop through the names of the interfaces? Like "ether1 ether2 ether3 ether4 ether5 sfp1"? I can also use the 'or' operator of course. But now I have this idea of looping by interface name, I'm interested in the possibilities.

I'm a bit stuck with this: `:foreach int in=[/interface print where type=ether] do={put $int}`, of course using print will create a total overview. But leaving it out doesn't do much good either.
 
2frogs
Forum Veteran
Forum Veteran
Posts: 713
Joined: Fri Dec 03, 2010 1:38 am

Re: Create list of interfaces in a loop  [SOLVED]

Sat May 16, 2020 5:54 pm

:foreach i in=[/interface bridge port find where bridge="bro"] do={/interface bridge port set $i pvid=10}
:D
 
AquaL1te
newbie
Topic Author
Posts: 32
Joined: Mon Sep 16, 2019 9:05 am

Re: Create list of interfaces in a loop

Sun May 17, 2020 5:43 pm

:foreach i in=[/interface bridge port find where bridge="bro"] do={/interface bridge port set $i pvid=10}
:D
Thanks! I see how this mechanism works now. It uses the indexes for the commands. I had that as a result before. But I was fishing for a list of interface names. But of course, this does the exact same thing :)

Who is online

Users browsing this forum: No registered users and 63 guests