[admin@MikroTik] > /interface print where name=loopback
Flags: D - dynamic, X - disabled, R - running, S - slave
# NAME TYPE MTU L2MTU
6 R loopback bridge 1500 65535
[admin@MikroTik] > :local x [/interface find name=loopback]; /interface set $x mtu=1480;
[admin@MikroTik] > /interface print where name=loopback
Flags: D - dynamic, X - disabled, R - running, S - slave
# NAME TYPE MTU L2MTU
6 R loopback bridge 1480 65535
:local interfaces [/interface find]; :put ("There are " . [:len $interfaces] . " interfaces total"); :foreach interface in=$interfaces do={ :put ("Interface name: " . [/interface get $interface name]); };
by the way, just checked with v4.2:The ID is only known after 'print' commands and is only used in direct CLI commands, and never in scripts.
:log info [/interface get 12 name];
:foreach i in=[/interface ethernet find] do={ :put [/interface ethernet get $i name]; }
I want to print a subset of the inetrfaces via script, i.e. something like: "/interface print where name="ether*"
/interface print where name~"^ether"
I want to print a subset of the inetrfaces via script, i.e. something like: "/interface print where name="ether*"Code: Select all/interface print where name~"^ether"
Hi Chupaka, I need write some script to rename ALL interfaces in router to DEFAULT-NAME.
Ex.: if some idiot renamed interface ether1 to eth00, I need script for rename this interface back to "ether1"....
/interface
:foreach counter=id in=[find default-name~"ether|wlan"] do={set $id name=[get $id value-name=default-name]}
It's like any other programming language, each has its own specifics. So I basically maintain some basic knowledge regarding what is possible in that language and what are its distinctive points, and then it is a matter of try and failHow you guys learned this scripting ? I mean...training directly in ROS and debuging is awful...
How you doing that ?
Hi Chupaka, I need write some script to rename ALL interfaces in router to DEFAULT-NAME.
Ex.: if some idiot renamed interface ether1 to eth00, I need script for rename this interface back to "ether1"....Code: Select all/interface :foreach counter=id in=[find default-name~"ether|wlan"] do={set $id name=[get $id value-name=default-name]}
Yes, I have debugged it on my router, what exactly goes wrong when you use it?Code: Select all/interface :foreach counter=id in=[find default-name~"ether|wlan"] do={set $id name=[get $id value-name=default-name]}
did you tape correct that command, can you double check please?
Thanks
Yes, I have debugged it on my router, what exactly goes wrong when you use it?Code: Select all/interface :foreach counter=id in=[find default-name~"ether|wlan"] do={set $id name=[get $id value-name=default-name]}
did you tape correct that command, can you double check please?
Thanks
The first (highlighted ") happens to me if I type the command at / level, because there, the default-name has no meaning.Yes, I have debugged it on my router, what exactly goes wrong when you use it?Code: Select all/interface :foreach counter=id in=[find default-name~"ether|wlan"] do={set $id name=[get $id value-name=default-name]}
did you tape correct that command, can you double check please?
Thanks
/interface {:foreach counter=id in=[find default-name~"ether|wlan"] do={set $id name=[get $id value-name=default-name]}}
The first (highlighted ") happens to me if I type the command at / level, because there, the default-name has no meaning.Yes, I have debugged it on my router, what exactly goes wrong when you use it?Code: Select all/interface :foreach counter=id in=[find default-name~"ether|wlan"] do={set $id name=[get $id value-name=default-name]}
did you tape correct that command, can you double check please?
Thanks
Can you enter "/interface" and try again from that level?
Or you may do that in a single line the following way:Code: Select all/interface {:foreach counter=id in=[find default-name~"ether|wlan"] do={set $id name=[get $id value-name=default-name]}}
thank you, you are just awesomeIt's like any other programming language, each has its own specifics. So I basically maintain some basic knowledge regarding what is possible in that language and what are its distinctive points, and then it is a matter of try and failHow you guys learned this scripting ? I mean...training directly in ROS and debuging is awful...
How you doing that ?
I highly recommend using ssh as RouterOS uses coloring to warn you that something you type is not correct (yet). This is also true if you use WebFig but the colors are much more pale (vyblitý would be a more accurate expression). And I use the [tab] key often to get context help.
I guess you may also talk to @jarda regarding a training.
Nice tip, some example ?Just a little remark: generally, I would first rename interfaces to "default_name.temporary_suffix", and then finally to "default_name". Because if, for example, ether1 was renamed to ether2 and ether2 was renamed to ether1 - the script will fail![]()
To si děláš srandu... the example is to simply use the same script twice, once translating the default names to a set of names which are guaranteed to differ from the existing ones (through using a suffix to the default name such as .befelemepeseveze, as @Chupaka has suggested), and then to run it once again with the final names. The Mikrotik scripting manual tells you how to concatenate strings so that you could append the suffix to the default names obtained using "get".Nice tip, some example ?Just a little remark: generally, I would first rename interfaces to "default_name.temporary_suffix", and then finally to "default_name". Because if, for example, ether1 was renamed to ether2 and ether2 was renamed to ether1 - the script will fail![]()
![]()
:global inName [/interface ethernet get number=0 name];
:put $inName