junbr0
May 12, 2025, 11:49am
1
hello ..
5 port RB (v6.49.18) with existing name :
ether1.recovery
ether2.br1.79.0/24
ether3.br1.79.0/24
ether4.br1.79.0/24
ether5.uplink
manual .. without loop for i
/interface bridge port;
:do { add bridge=$br1 interface=$if2 hw=yes disabled=no } on-error={/log info "port bridge existed"}
:do { add bridge=$br1 interface=$if3 hw=yes disabled=no } on-error={/log info "port bridge existed"}
:do { add bridge=$br1 interface=$if4 hw=yes disabled=no } on-error={/log info "port bridge existed"}
the code that not yet correct, my try…
:local br1 "ether2.br1.switch"
:for i from=2 to=4 do={[/interface bridge port add bridge=$br1 interface="ether$i.br1.79.0/24" disabled=no hw=yes] \
on-error=[/log info "bridge port $i existed"]}
failure: device already added as bridge port;
on log : bridge port 2 existed.
the loops stop at first and not continue to next.
so whats wrong ? *please just simple …
pardon my english
best regards
/interface bridge port export
what show?
showing this :
/interface bridge port
add bridge=ether2.br1.switch interface=ether2.br1.79.0/24
add bridge=ether2.br1.switch interface=ether3.br1.79.0/24
add bridge=ether2.br1.switch interface=ether4.br1.79.0/24
So, the error message is correct, what do you expect?
my question to be simple : how to loops "for i" this or any loops better approachment ?
/interface bridge port;
:do { add bridge=$br1 interface=$if2 hw=yes disabled=no } on-error={/log info "port bridge existed"}
:do { add bridge=$br1 interface=$if3 hw=yes disabled=no } on-error={/log info "port bridge existed"}
:do { add bridge=$br1 interface=$if4 hw=yes disabled=no } on-error={/log info "port bridge existed"}
thank you
If these interfaces are ALREADY in the bridge, you will get an error even if you try to add one manually.
I.e. what happens if you run on terminal just:
/interface bridge port
add bridge=ether2.br1.switch interface=ether2.br1.79.0/24
You should remove all those interfaces before running your script (or the above manually).
hw=yes disabled=no
are defaults, so, completely useless.
:global GconnEth "ether1" ; # WAN interface
:global GmgmtEth "ether5" ; # MGMT interface
/int bridge
remove [find]
add name=bri-lan protocol-mode=none
/int bridge port
remove [find]
:foreach iTest in=[/int ethernet find where name!=$GconnEth and name!=$GmgmtEth] do={add bridge=bri-lan interface=$iTest}
/int bridge
set bri-lan admin-mac=[/int ethernet get [/int bri port get ([find]->0) interface] mac-address] auto-mac=no
so correct logic in mikrotik v6 you must remove then re add the port … *LoL
then its better not through loop sequence i think.
gonna try your example script tomorrow… thanks rextended and jaclaz
The logic of anything would be that they should not already be bridged ports before trying to put them in again…
The script assumes to configure a device that has never been configured, not to modify something that already exists…
jaclaz
May 12, 2025, 3:29pm
10
Yep, but it is not specific to v6, it is the “add” command that assumes that you cannot (re-) add something that already exists..
Conversely, you could try checking if the interface already exists and if it exists NOT add the same interface, it depends in which context the script is run, if it is a sort of setup script it is better to make sure that there are no interfaces on the bridge and add the wanted ones.
junbr0
May 14, 2025, 9:24am
11
so rextended teaching me new thing command to ‘flush’ interface bridge port
/interface bridge port;
remove [find];
:for i from=2 to=4 do={[/interface bridge port add bridge=$br1 interface="ether$i.br1.79.0/24" disabled=no hw=yes] \
on-error=[/log info "bridge port $i existed"]}
mikrotik oddities…*LoL
solved…! ( how to close this thread?)
regards,
jaclaz
May 14, 2025, 12:51pm
12
You should have, top right of posts an icon like a green check mark.
If you hover over it you will see “accept this answer”.
Click on the check mark of the post by rextended that put you on the right track.
That post will get a green border and the thread will have added a green [SOLVED} .