Compare RouterOS version in script

I need help to test for routerOS version. Since 7.10xxx user the new time format, how do I test for 7.10 or newer.

7.8 no
6.49 no
7.1 no
7.10beta5 yes
7.10rc1 yes
7.24 yes
8.1beta22 ok

Tried to extract the routerOS version, but not sure how to make a regex true that will work on all version.
It has been simpler if 7.1 was named 7.01

tonum does not work with decimal.

This just removes the first dot
[
:local ver [/system resource get version]
:local dot [:find $ver “.”]
:local new “$[:pick $ver 0 $dot]$[:pic $ver ($dot + 1) 99]”
:put $new
]

This gives 710beta5 (development)
I can remove beta5… using a for each loop, but still how to test against 710 and not get error with 71 (fail) vs 711 (ok)
There mest be a simpler way to do this?

On [/system resource get version] is not indicated the build-time

On [/ip neighbor] version is all together like “7.7 (stable) Jan/12/2023 07:35:45

This function convert version from system or from neigbot to one array and keep same info (major, minor, patch, channel, build-time) on same position.

:global version2arr do={
:local ver [:tostr $1]
:local pos 0
:local major “” ; :local minor “”; :local patch “” ; :local chnnl “” ; :local build “” ; :local btime “”
:set pos [:find $ver “.” -1]
:set major [:pick $ver 0 $pos]
:set ver [:pick $ver ($pos + 1) [:len $ver]]
:if ([:typeof [:find $ver “.” -1]] != “nil”) do={
:set pos [:find $ver “.” -1]
:set minor [:pick $ver 0 $pos]
:set ver [:pick $ver ($pos + 1) [:len $ver]]
}
:if ([:typeof [:find $ver " " -1]] != “nil”) do={
:set pos [:find $ver " " -1]
:if ($minor = “”) do={
:set minor [:pick $ver 0 $pos]
} else={
:set patch [:pick $ver 0 $pos]
}
:set ver [:pick $ver ($pos + 1) [:len $ver]]
}
:if ([:typeof [:find $ver “(” -1]] != “nil”) do={
:set pos [:find $ver “)” -1]
:set chnnl [:pick $ver 1 $pos]
:set ver [:pick $ver ($pos + 1) [:len $ver]]
}
:if ($ver ~ "^ ") do={
:set btime [:pick $ver 1 [:len $ver]]
} else={
:set btime $ver
}
:return ($major,$minor,$patch,$chnnl,$btime)
}
> :put [$version2arr [/system resource get version]]
6;48;6;long-term

> :put [$version2arr [/system resource get version]]
7;7;;stable

> :put [$version2arr “7.7 (stable) Jan/12/2023 07:35:45”]
7;7;;stable;Jan/12/2023 07:35:45

> :put [$version2arr “7.10beta5 (development) 2023-05-03 14:33:19”]
7;10beta5;;development;2023-05-03 14:33:19
About development versions, the minor version is 10beta5, but some subsequents division is possible, but for me is excessive.

Thanks. That was a short and simple solution to get the version :wink:

MT should make this as a simple and output should be numeric 7.01 7.11 etc instead of 7.1 and 7.11

I have a function that converts the version to a numerical value:
https://git.eworm.de/cgit/routeros-scripts/tree/global-functions.rsc?id=9069f71ee6168a651fd42f90b7aea309fefa260b#n1269

[admin@MikroTik] > :put [ $VersionToNum 7.9 ]
118095616
[admin@MikroTik] > :put [ $VersionToNum 7.10beta5 ] 
118120197
[admin@MikroTik] > :put ([ $VersionToNum 7.9 ] > [ $VersionToNum 7.10beta5 ])
false

This works with all versions, including “alpha”, “beta” and “rc”.

Thanks, will try it out.

Your scripts are some overwhelming :slight_smile:
Can you point me where to find the CharacterReplace part? Without need to install everything.

(the date of 10 beta 5 build time is approx, I do not rememmber the correct value)

If you want convert the version to a number, just for compare two numbers, you can do two things:

Convert build date to Unix Epoch, like
7.7 (stable) Jan/12/2023 07:35:45 ==>> 1673508945 (GMT)
7.10beta5 (development) 2023-05-09 13:38:22 ==>> 1683639502 (GMT)

datetime2epoch is here >> http://forum.mikrotik.com/t/i-did-it-script-to-compute-unix-time/68576/24
{
:local a [$datetime2epoch [/system resource get build-time]] ; # read current RouterOBARD value
:local b [$datetime2epoch “Dec/03/2021 12:15:05”] ; # from RouterOS 6.48.6
:local c [$datetime2epoch “2023-05-09 13:38:22”] ; # from RouterOS 7.10beta5
:put ($a > $b)
:put ($b < $c)
:put ($a < $c)
}
And spitting again the patch value only if is present “alpha”, “beta”, or “rc”:
2h)
convert the vesion based on numbers, like what @eworm do:
7.7 stable (is implicit 7.7.0 stable 0) ==>> 7 * 0x10000000 + 7 * 0x100000 + 0 * 0x1000 + “stable = 0x300” + 0 = 0x070700300 (on decimal is 1886388992)
7.10beta5 development (is implicit 7.10.0 beta 5) ==>> 7 * 0x10000000 + 10 * 0x100000 + 0 * 0x1000 + “beta = 0x200” + 5 = 0x071000205 (on decimal is 1895825925)

2d)
or convert it to decimals (is more readable than hex…)
7.7 stable (is implicit 7.7.0 stable 0) ==>> 7 * 10000000 + 7 * 100000 + 0 * 1000 + “stable = 300” + 0 = 70700300 (on hex is 0x436CD0C)
7.10beta5 development (is implicit 7.10.0 beta 5) ==>> 7 * 10000000 + 10 * 100000 + 0 * 1000 + “beta = 200” + 5 = 71000205 (on hex is 0x43B608D)

https://git.eworm.de/cgit/routeros-scripts/tree/global-functions.rsc?id=9069f71ee6168a651fd42f90b7aea309fefa260b#n155

I was just stopping by to say thanks for the $CharacterReplace and $VersionToNum functions, they are very useful.

Thanks for sharing!

Glad I could help, you are welcome.

If you find this useful have a look at all my RouterOS Scripts