Community discussions

MikroTik App
 
DejanAgain
just joined
Topic Author
Posts: 10
Joined: Fri May 10, 2019 12:01 am

Are manuals updated ?

Mon Nov 21, 2022 8:29 pm

Hi,

I just tried to apply script which was not using for a while and this is not working, as resume :

Script was working on 6.x.x and now this is not working on 7.6.

In few debug attempts I detected that following is not working anymore :

:global printpserverip [/system ntp client get primary-ntp]

looks like under "/system ntp client" not exists anymore "primary-ntp" and this is replaced with "servers"

Also, few wiki pages are outdated, I just checked following and can not understand is this is for 7 or this is outdated. Is there any new version compatible with router os 7.x ?
https://help.mikrotik.com/docs/pages/vi ... d=40992869

Another question is :
Is there any built in function to split string, for example from "servers" "1.1.1.1,2.2.2.2" y want to get first one ip to variable.

Thank you in advance,
Dejan
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Are manuals updated ?

Mon Nov 21, 2022 11:14 pm

To see what you can get out of the NTP, just past this to terminal
:put [/system ntp client get]
You should get some like this:
enabled=true;freq-drift=3529;mode=unicast;servers=199.41.243.43;80.89.32.122;status=synchronized;synced-server=199.41.243.43;synced-stratum=2;system-offset=1513;vrf=main
To get what server you have synced to:
:put [/system ntp client get synced-server]
To get configured servers.
:put [/system ntp client get server]
To get first element, convert to array and pick number 0
:put [:pick [:toarray [/system ntp client get server]] 0]
Edit:
Since its already an array, you can do:
:put [:pick [/system ntp client get server] 0]
For your variable:
:global printpserverip [:pick [/system ntp client get server] 0]
PS if there are no need for use the variable later or in another script, use local vaiable:
:local printpserverip [:pick [/system ntp client get server] 0]
Last edited by Jotne on Mon Nov 21, 2022 11:21 pm, edited 4 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Are manuals updated ?

Mon Nov 21, 2022 11:15 pm

(serverS)

some examples:
:put ([:toarray "1.1.1.1,2.2.2.2"]->0)

:put ([:toarray "1.1.1.1,2.2.2.2"]->1)

:put ([/system ntp client get servers]->0)

:put ([/system ntp client get servers]->1)

:foreach server in=[/system ntp client get servers] do={
    :put $server
}
 
DejanAgain
just joined
Topic Author
Posts: 10
Joined: Fri May 10, 2019 12:01 am

Re: Are manuals updated ?

Tue Nov 22, 2022 6:49 am

Thank you both, very useful examples for array handling.

Who is online

Users browsing this forum: No registered users and 18 guests