Page 1 of 1

RouterOS version dependent backup script

Posted: Fri Jan 21, 2022 2:31 am
by leonardogyn
Hello Everyone,

I'm trying to change my automatic backup script from RouterOS 6.x to 7.x to add the 'show-sensitive' parameter that's now required on ROS7. Previously, on ROS6, I would need to issue hide-sensitive if want to hide those informations. On ROS7, those informations are hidden by default and I need to ask for them (show-sensitive).

I tried to edit my backup script to get ROS major (6 or 7), and doing the export based on that, something like:
:local ROSver value=[:tostr [/system resource get value-name=version]];
:local ROSmajor value=[:pick $ROSver 0 ([:find $ROSver "." -1]) ];
# ROSmajor will be only 6 or 7, 100% tested
:if ( $ROSmajor = 6 ) do={ /export terse file=$nomearquivo; } else={ /export terse show-sensitive file=$nomearquivo; }
and that worked fine on ROS7, that was correctly doing the export with 'show-sensitive' parameter.

On ROS6, however, the script gives an error and never runs, despite that 'else' will never be reached. Seems the script is being "compiled" or "analyzed" before run. And that being made, the 'show-sensitive' does not exist on ROS6, which triggers the error.

Question is: how could I acchieve a 'version-dependent' (based on ROS major) script, that would be exactly the same on ROS6 and ROS7, and yet do different things, being the commands on one ROS version maybe invalid on the other version? Is that possible?

Thanks for all your hints :)

Re: RouterOS version dependent backup script  [SOLVED]

Posted: Fri Jan 21, 2022 1:43 pm
by msatter
Changed the code so that is executable in as one and moved the ROS 6 syntax incompatible show-sensitive to a string variable. So that no syntax check is done on that incompatible line.
{
:local ROSver [:tostr [/system resource get value-name=version]];
:local ROSmajor [:tonum [:pick $ROSver 0 1]];
# ROSmajor will be only 6 or 7, 100% tested
:local showsen "/export terse file=$nomearquivo show-sensitive"
:if ( $ROSmajor = 6) do={ /export terse file=$nomearquivo; } else={ $showsen }
}