Community discussions

MikroTik App
 
leonardogyn
just joined
Topic Author
Posts: 18
Joined: Wed Dec 04, 2019 4:47 pm

RouterOS version dependent backup script

Fri Jan 21, 2022 2:31 am

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 :)
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: RouterOS version dependent backup script  [SOLVED]

Fri Jan 21, 2022 1:43 pm

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 }
}

Who is online

Users browsing this forum: GoogleOther [Bot] and 22 guests