Syntax difference in versions, how to handle?

This is a conundrum since MikroTik decided to change the behavior of /export terse
I don’t mind the change in itself but the problem is how do I handle this with a single line? Using 2 lines will not work as it will include the output in the config backup

So at first I thought I could use this, which detects if its v6 or not and then run 1 command or the other appropriately

:if ([/system package get 0 version] ~ "^6") do={/export terse} else={/export terse show-sensitive}

But it doesn’t work because it errors out due a syntax error, as ‘show-sensitive’ is not a valid parameter in V6 and its parsing what is in the else= field and determining it as invalid syntax and not running the code at all
Is there any way to handle this? I’m not sure if it there is a way to parse a string as command? Or any other way to handle this that is both V6 and V7 compatible?

Simple solution, keep routers up to date :slight_smile:

Think what you write, Normis. ROS v.6 is still supported, it means 6.49.11 is up to date.

Not really. It receives critical vulnerability fixes, but there is no technical support / help for it.

v7 is stable

v7 is still beta at best and definitely not a full replacement for v6

Besides, managing a dozen routers that you own is fine, managing hundreds/thousands of devices it’s just not practical to enforce an upgrade to v7 (that then breaks other things) that sort of idea is nonsensical

Does :execute command exists in ROS6?

You try with it if does,

:if ([/system package get 0 version] ~ "^6") do={:execute "/export terse" as-string} else={:execute "/export terse show-sensitive" as-string}

Syntax will not be checked in string for execute, it will only break execute if is wrong syntax in it.

False and misinformation.

An example of all the things that are missing on v7, which are instead present on v6, which therefore do not make it possible to install v7, (ignoring BGP & Co.)…

Where is user-manager on v7?

Not something called “use-manager”, but something that have same functionality as user-manager on v6

(I’m not saying that v7 doesn’t work, but that it doesn’t have all the same features as v6, although other things have been added on v7 [useless or not])

Please stop writing on this way, no matter if is only one example.

Why? It's entirely valid in this example, there will ALWAYS be at least 1 package, and packages have the same version number (but may change in name, thus 0 is perfectly suited)
If it was something like a firewall rule then yeah no, fully agree. But in this example its just being pedantic

More than happy for you to show me a scenario where 'get 0' will not work as expected in this case

Don’t read what I didn’t write, that is in general, not in this specific case.

This turned out to be the correct answer, use the :execute command which does work with variables. So this is what i’m using in scripts

I’m using the following to get actual/major/minor revisions. This allows integer comparisons for specific changes such as 7.13+ wifi drivers
RouterOS = 7.13.3 (strips the " (Stable)")
RouterOSMajor = 7
RouterOSMinor = 13


:global RouterOS [:pick [/system resource get version] 0 [:find [/system resource get version] " "]]
:global RouterOSMajor [:pick $RouterOS 0]
{
:local o
:local a ([:find $RouterOS "."]+1)
:local b ([:find $RouterOS "." $a])
:if ($b > 0) do={:set $o [:pick $RouterOS 0 $b]} else={:set $o $RouterOS}
:global RouterOSMinor [:pick $o 2 [:len $o]]
}



v6 or v7 commands…

:if ($RouterOSMajor > 6) do={
:global C "/export terse"
} else={
:global C "/export terse show-sensitive"
}
execute $C ; /system script environment remove C

Sub version specifics…

:if ($RouterOSMajor = 6) do={
 :if ($RouterOSMinor <= 42) do={
  :global C "/log warning \"RouterOS Insecure, Please Update\""
 }
 :if ($RouterOSMinor > 42 and $RouterOSMinor <= 49) do={
  :global C "/log warning \"Happy Days\""
 }
 :if ($RouterOSMinor > 49) do={
  :global C "/log warning \"Living in the future\""
 }
}
:if ($RouterOSMajor = 7) do={
  :global C "/log warning \"Still in beta testing, all new RB4011's are sad panda's\""
}
execute $C ; /system script environment remove C

This use of :execute for v6/v7 compatibility should be in the scripting manual!