We are using 2 types of radios: “BaseBox 2” & “Metal 2SHPn”
We’d like to write a single script to configure them, but the problem is that the OS tries to interpret the lines that will NOT be executed and fails Ex:
:global Board [/system resource get board-name];
...
:if ($Board = "BaseBox 2") do={ /interface wireless set 0 rx-chains=0,1 tx-chains=0,1 }
This code fails on the “Metal 2SHPn” because there is no “rx-chains / tx-chains” with:
Script file loaded successfully Expected end of command (line 223 column 64)
Is there a way to tell the OS “Don’t interpret lines you won’t run” or something to allow us to combine our scripts ?
I’ve tried embedding the error catching as you have described, but I still have the same issue.
I’ve also upgraded the RouterOS to the latest on the “Metal 2SHPn” just in case and the same result…
Any other idea ?
I don’t want to start breaking out this script into many small one, say { Core functions, MetalOnly, BaseBoxOnly } and call them as external scripts because the whole idea was to SIMPLIFY and be able to transfer a single script instead this script for BaseBox and that script for Metal.
Script file loaded successfully Expected end of command (line 223 column 64)
would indicate a syntax problem with the script.
Can you post the relevant lines and any error messages from the log. If you need additional logging just add the script option to the log.
Yes it is a syntax error,
but only from the point of view of the “Metal 2SHPn” because this script runs just fine on the “BaseBox 2”.
But that’s what I’m trying to do:
Somehow have a single script that sets-up multiple Mikrotik hardware the same way Network-wise,
but that is also specific for each hardware so I can get the best performance out of them
(Ex: turn on the second chain on the BaseBox 2).
This sounds like a job for dynamic scripting. It’s a bit more advanced, however it looks like it can be used to solve your problem.
Please be careful of the spaces at the end of the strings, they are required.
Make sure to replace the default-name of your wireless interface if it’s different, this is the internal interface name not the one you’ve assigned to it.
:local Board [/system resource get board-name]
:local configcmd
# Caution don't rely on the set indexer (e.g. set 0)
:local cmdstart "/interface wireless set [ find default-name=wlan1 ] "
:local radiochains "rx-chains=0,1 tx-chains=0,1 "
# Here you could add more config parameters to the wireless
# Example shows setting SSID and Broadcast band
:local ssid "ssid=YOUR-SSID "
:local band "band=2ghz-b/g/n "
:do {
# Chain the commands together to form a coherent command
:if ($Board = "BaseBox 2") do={
:set $configcmd ($cmdstart.$radiochains.$ssid)
}
:if ($Board = "Metal 2SHPn") do={
:set $configcmd ($cmdstart.$band.$ssid)
}
# Dynamically execute the command
[:parse $configcmd]
# Log the command
:log info "Executed command $configcmd for $Board"
} on-error={:log error "Could not configure wireless settings"}
Yes ! That works.
This piece of code can be simplified and a lot of error trapping could be removed.
#--- Enable second chain for Basebox 2 only, but without making a syntax error for the Metal.
:do {
:local DynamicCommand
:if ($Board = "BaseBox 2") do={
:set $DynamicCommand "/interface wireless set 0 rx-chains=0,1 tx-chains=0,1"
[:parse $DynamicCommand]
:log info "Executed $DynamicCommand on $Board"
}
} on-error={:log error "Setting Chains failed on dynamic command"}