I have a standard script that I use to configure Mikrotiks in my work.
I’m trying to adapt the script so that would work in ROS6 and ROS7, but i’m not having lucky when testing this part on latest version of ROS7.
The code is supposed to result in error in one of the versions, that’s why I’m using “on-error”.
The problem is that the error is not being handled as I programmed in code, instead it only shows that that is having an error.
Am I making this wrong? Appreciate the help.
expected end of command (line 6 column 20)
# NTP
do {
/system
clock set time-zone-name=Greenwich
ntp client set enabled=yes
ntp client set primary-ntp=0.0.0.0
ntp client set secondary-ntp=0.0.0.0
} on-error= { :put "Ignoring - RouterOS v7" }
do {
/system
clock set time-zone-name=Greenwich
ntp client set enabled=yes
ntp client servers add address=0.0.0.0
ntp client servers add address=0.0.0.0
} on-error={ :put "Ignoring - RouterOSv6" }
Instead of using on-error, find out what version of RouterOS the router is running and the run the correct part with if:
Sample code to see main version:
{
:local ver [:tonum [:pick [/system resource get version] 0 1]]
:put $ver
}
Actually it’s not working, when I test on v6 it shows error on the line of v7 and when I test on v7 it shows error on the line of v6.
I thought that using a condition, the part that doesn’t match would be ignored, but it doesn’t work that way.
It’s possible to make this work somehow? Or RouterOS will always interpret the whole script?