Community discussions

MikroTik App
 
millenium7
Long time Member
Long time Member
Topic Author
Posts: 539
Joined: Wed Mar 16, 2016 6:12 am

Syntax difference in versions, how to handle?

Thu Jan 11, 2024 8:24 am

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?
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26387
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Syntax difference in versions, how to handle?

Thu Jan 11, 2024 9:15 am

Simple solution, keep routers up to date :)
 
User avatar
karlisi
Member
Member
Posts: 443
Joined: Mon May 31, 2004 8:09 am
Location: Latvia

Re: Syntax difference in versions, how to handle?

Thu Jan 11, 2024 10:49 am

Think what you write, Normis. ROS v.6 is still supported, it means 6.49.11 is up to date.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26387
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Syntax difference in versions, how to handle?

Thu Jan 11, 2024 11:14 am

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

v7 is stable
 
millenium7
Long time Member
Long time Member
Topic Author
Posts: 539
Joined: Wed Mar 16, 2016 6:12 am

Re: Syntax difference in versions, how to handle?

Thu Jan 11, 2024 11:26 am

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
 
optio
Long time Member
Long time Member
Posts: 675
Joined: Mon Dec 26, 2022 2:57 pm

Re: Syntax difference in versions, how to handle?  [SOLVED]

Thu Jan 11, 2024 11:38 am

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.
Last edited by optio on Thu Jan 11, 2024 11:47 am, edited 1 time in total.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26387
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Syntax difference in versions, how to handle?

Thu Jan 11, 2024 11:45 am

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
False and misinformation.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Syntax difference in versions, how to handle?

Thu Jan 11, 2024 12:34 pm

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])
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Syntax difference in versions, how to handle?

Thu Jan 11, 2024 12:37 pm

get 0
Please stop writing on this way, no matter if is only one example.
 
millenium7
Long time Member
Long time Member
Topic Author
Posts: 539
Joined: Wed Mar 16, 2016 6:12 am

Re: Syntax difference in versions, how to handle?

Thu Jan 11, 2024 12:46 pm

get 0
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
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Syntax difference in versions, how to handle?

Thu Jan 11, 2024 1:00 pm

Don't read what I didn't write, that is in general, not in this specific case.
 
millenium7
Long time Member
Long time Member
Topic Author
Posts: 539
Joined: Wed Mar 16, 2016 6:12 am

Re: Syntax difference in versions, how to handle?

Mon Feb 05, 2024 2:22 am

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.
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
 
mt99
newbie
Posts: 44
Joined: Wed Jan 03, 2018 6:07 pm

Re: Syntax difference in versions, how to handle?

Mon Feb 05, 2024 4:46 am

: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.
This use of :execute for v6/v7 compatibility should be in the scripting manual!

Who is online

Users browsing this forum: No registered users and 7 guests