Script for all ROS versions

Hi,
on the 6.14 realse:

What’s new in 6.14 (2014-Jun-06 15:34):

*) sntp - ‘mode’ now is a read-only property, it is set to broadcast if no
server ip address is specified;

How to do a script that Works with all OS versions.

I have a Script working with with <6.14:
/system ntp client
set unicast=yes enabled=yes primary-ntp=xxxx secondary-ntp=
xxxx

For >=6.14 should be (other case script doen’t load):
/system ntp client
set enabled=yes primary-ntp=xxxx secondary-ntp=
xxxx

I need a script for all versions how to do it …

Thank’s

Can be used to check any version of routeros.

6.7 = numeric version 607
6.14 = numeric version 614
6.17 = numeric version 617

From 3.x no other “2 point” version like 2.9.27

This function obviously not count “rc” version and other.

:global ROSver value=[:tostr [/system resource get value-name=version]];
:global ROSverH value=[:pick $ROSver 0 ([:find $ROSver "." -1]) ];
:global ROSverL value=[:pick $ROSver ([:find $ROSver "." -1] + 1) [:len $ROSver] ];
:if ([:len $ROSverL] < 2) do={ set $ROSverL value=("0".$ROSverL) };

:global ROSverN value=[:tonum ($ROSverL.$ROSverL)];

/system ntp client set enabled=yes primary-ntp=1.1.1.1 secondary-ntp=2.2.2.2;

:if ($ROSverN < 614) do={
 /system ntp client set unicast=yes;
};

Shorter version:

/system ntp client set enabled=yes primary-ntp=XXXX secondary-ntp=XXXXX

:global unicastYes [:parse "/system ntp client set unicast=yes"]
:do {$unicastYes} on-error={}

If command set unicast=yes in last line generates an error we just ignore it and script will continue.

Explanation:
http://wiki.mikrotik.com/wiki/Manual:Scripting#Catch_run-time_errors

Obviously my script want be one way for test on what routeros version the script is running.

If you want make one shorter version, do really:

/system ntp client set enabled=yes primary-ntp=1.1.1.1 secondary-ntp=2.2.2.2;
:do { [:parse "/system ntp client set unicast=yes"] } on-error={ };

But you must test first if is runner under routeros 6.2+ because the command is unsupported on previous routeros version.

Thanks for cooperation :slight_smile:. Now I think it is the shortest version possible. :slight_smile:

RouterOS 6.2 was released one year ago. I guess it is safe to assume that nobody uses it anymore. :slight_smile:

Ehh… no. That’s not how RouterOS upgrades tend to work.

First off, you have all routers with old licenses that aren’t upgraded to 6., but are staying at 5.. Then there’s also people who don’t upgrade even when they can, because 6.* has had (and some may argue still has) a bumpy start.

That said, people who have AT ALL started at the 6.* branch have probably already upgraded way past 6.2. I for one am at 6.9 currently, and will upgrade either when a version isn’t immediately followed by posts saying “OMFG, [something] broke down with the upgrade!”, or if there’s a fix in there that I actually care enough about.


As long as you clarify in comments or whatever that the script requires 6.2 at minimum, I think everyone using it will be all right :wink: .

Now, we have it all clarified. :wink: