ROSv7 /system/ntp/client set servers=$var1,$var2

I’ve had RB951Ui-2HnD boxes running ROSv6 for years. One of my startup scripts on these devices sets NTP servers with e.g. [:resolve 0.pool.ntp.org]

I sett that the NTP Client setup has changed in ROSv7, and manually at the command line I can type:

/system ntp client set servers=92.113.12.77,5.250.184.159

and it works fine. But in a script:

:local NTPPoolServer1
:local NTPPoolServer2
:set NTPPoolServer1 [:resolve 0.pool.ntp.org]
:set NTPPoolServer2 [:resolve 1.pool.ntp.org]
:put $NTPPoolServer1
:put $NTPPoolServer2
/system ntp client set servers=$NTPPoolServer1,$NTPPoolServer2

.. produces the error in the /log:

script,error executing script NTP Pool from www failed, please check it manually
script,error,debug expected end of command (line 7 column 47)

If I remove the “,$NTPPoolServer2” from the last line of the script (so that I’m only setting one server) the script succeeds.

I’m sure I’m being stupid and missing something…

How am I being stupid and what am I missing, to allow the /system/ntp/client set servers= command in the script to take two comma-separated variables, please?

thank you.

I think you'll have to format it either as a list or a string. E.g. servers=($a . "," . $b)

Also, the ntp client has no problems taking dns names directly...

not, wrong approach, for me, read next

Simply

For EASY ADD (or REPLACE, see comment inside):

/system ntp client servers
# remove [find where !dynamic] ; # uncomment this line for remove previous servers
add address=0.pool.ntp.org
add address=1.pool.ntp.org

For REPLACE anything existing, with new:

/system ntp client set servers=("0.pool.ntp.org","1.pool.ntp.org")

Both recalc the DNS on TTL, so everytime use the correct NTP as the ntp.org rules

1 Like

It does work, though. Yours is of course much nicer.

1 Like

Ok, but add ( ) suffice, without involving other items...
It's the initial OP concept that's wrong...

I finished the descriptive post (ROSv7 /system/ntp/client set servers=$var1,$var2 - #4 by rextended), I hope the English is understandable.

Don't worry... next time set manually the values on winbox, and use export for know the correct commands...

/system/ntp> export 
# 2026-02-18 15:32:19 by RouterOS 7.16.2
# software id = 
#
/system ntp client
set enabled=yes
/system ntp client servers
add address=0.pool.ntp.org
add address=1.pool.ntp.org

Thanks everyone. The set servers=($var1,$var2) works.

About why not use “add” commands, I assume (am I wrong?) that “add”ing would keep adding more and more servers. I just want, at boot and again every 24 hours or so, to refresh two servers. Thus my decision to use an explicit “set servers=” command instead of “add”.

Regarding the suggestion to use WinBox or WebFig and then export, that actually wouldn’t have answered the problem, because the export produces:

/system ntp client
set enabled=yes mode=unicast servers=92.113.12.77,5.250.184.159 vrf=main

.. which doesn’t address the nuance of having to create a ($list, $list) when using variables.

Again, thanks everyone!
RouterOS v7 is being .. an experience .. for me, after so many years on v6.

(I’m finally moving towards v7 in expectation of ever-shorter-TLS-certificate-lifetimes becoming a major management pain, and MikroTik support telling me that they do not intend to ever add automated certificate management to ROSv6 :frowning: ).

This is enough without unnecessary calculations.

/system ntp client set servers=("0.pool.ntp.org","1.pool.ntp.org")

Every time the server synchronizes, it relies on the TTL provided by the DNS.
The IPs on ntp.org are constantly changing to balance calls,
setting fixed IPs is detrimental to the proper functioning of the system.

It depends on the RouterOS version, which you forgot to specify.
If you read, my post mentions the 7.16.2 export.
If you act like "one version is the same as the other", the answers also have the same characteristics.

Just FYI, the output of the export command from which I observed that it wouldn’t have shown the ($necessary,$parenthesis) is long-term 7.20.8.

Fair point. Somehow I had it stuck in my head (I’m not even sure whether this was ever true ages ago in ROSv6) that the NTP client DIDN’T dynamically look up each time. I’ll switch to the DNS names.

You remember well... in RouterOS v6 it didn't accept DNS...

2 Likes