script to change bridge port

Hi,

I am trying to figure out how to make a script to change a bridge port, on netwatch.

I don’t quite understand how to get the number of the port, in a script by it’s name, because when you set something, it wants the number, not the name. This is what I have, but of course it doesn’t work. I don’t understand where you put “()” or “” or “{}” in scripting.

/interface bridge port set [get name interface=ether5] bridge=bridge-Fox-SU

thanks.

Glenn Allen

{ } is used for scope. Scope basically tells the OS the context for commands. By default all commands are run at the root context, “/”.

Your example is this:

/interface bridge port set [get name interface=ether5] bridge=bridge-Fox-SU

‘get’ fetches properties into variables, which isn’t what you’re trying to do. You’re looking to use find to return an item to set a property on. Both ‘set’ and ‘find’ are separate commands. You can specify everything as absolute paths:

/interface bridge port set [/interface bridge port find name interface=ether5] bridge=bridge-Fox-SU

Or you can use scope via { } to reset the context of all commands within the scope to “/interface bridge port”:

/interface bridge port { set [find name interface=ether5] bridge=bridge-Fox-SU }

I hope that makes sense now.

http://wiki.mikrotik.com/wiki/How_to_configure_a_home_router contains somewhat of a CLI tutorial.

Hi Fewi,

What you have shown me, makes sense, but I can’t get ether of these examples, to work. I have tried them locally on a new terminal session, and also as a script, and ran the script. No errors were displayed. It just doesn’t change the bridge group.

If I just do this:
/interface bridge port set 3 bridge=bridge-Fox-SU it works, but I don’t want to do the that it will be #3

So what am I doing wrong.

Thanks.

Glenn Allen

I’m sorry, I was blindly copying your example and didn’t fix all the errors. Use this:

/interface bridge port { set [find interface=ether5] bridge=bridge-Fox-SU }

Hi Fewi,

That works. I see that I have to be “exact” on the name, “ether5” was not good enough. I had to put the name as “ether5-local”

Thanks for the help

Glenn Allen

Yes, the ‘=’ operator compares values so that only exact values are true. You can also match on regular expressions with the ‘~’ operator:

find name~"ether5"