PR2 finding the last time sync done by the ntp daemon

Hi, so I’m trying to use a command to find the last time that the system time has been updated with an NTP server. What I know so far is that this command through secure shell(putty) “sudo grep -i ‘ntp’ /var/log/syslog” does seem to pull a log, but is there any other commands in your Linux operating system that would help me find the latest time sync?

Hi Talyn, welcome to the Opto22 forums.

Since you are clearly already setup with shell access, here is what I am pretty sure you are looking for:
First up, become sudo and then install the ntp utilities.

sudo su
apt-get update
apt-get install ntp-utils
ntpq -p

Thats going to return a table that looks a bit like this:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================  .POOL.          16 p    -   64    0    0.000    0.000   0.002  .POOL.          16 p    -   64    0    0.000    0.000   0.002  .POOL.          16 p    -   64    0    0.000    0.000   0.002
+dev.smatwebdesi     2 u  141 1024  377   37.411    1.291   0.819     3 u   22 1024  377   16.401   -1.489   0.327
- (   2 u  885 1024  377   63.962   -0.303   0.462
*time.nullrouten      2 u 1028 1024  377   11.861    0.197   0.553    2 u  321 1024  377   43.415   -0.319   0.501
-us2.timeserver.     2 u  538 1024  377   66.107   -1.521   0.215
-  4 u  643 1024  177   42.403   -1.762   0.429

A quick breakdown of each column:

The character that may be at the start of the remote hostname/IP address:
‘*’ indicates the current synchronization source.
‘#’ indicates that the host is selected for synchronization, but the distance from the host to the server exceeds the maximum value.
‘o’ indicates that the host is selected for synchronization and the PPS signal is in use.
‘+’ indicates the host is included in the final synchronization selection set.
‘x’ indicates that the host is the designated false ticker by the intersection algorithm.
‘.’ indicates that the host is selected from the end of the candidate list.
‘–’ indicates a host discarded by the clustering algorithm.
blank indicates a host is discarded due to high stratum and/or failed sanity checks.

  • remote: remote hostname or IP of NTP server, and its refid NTP server

  • st: stratum of server. 1 is the most accurate, down to 16 (16 means not synced)

  • t: type of server (l = local, u = unicast, m = multicast, b = broadcast)

  • poll: how frequently to query server (in seconds)

  • when: how long since the last poll (in seconds)

  • reach: octal bitmask of success or failure of last 8 queries (left-shifted); 377 = 11111111 = all recent queries were successful; 257 = 10101111 = 4 most recent were successful, 5 and 7 failed

  • delay: network round trip time (in milliseconds)

  • offset: the difference between the local clock and remote clock (in milliseconds)

  • jitter: difference of successive time values from the server (high jitter could be due to an unstable clock or, more likely, poor network performance)

You should be able to script something up that parses this table and extracts the data you want.
It would be perfect to use Python to do this vs Node-RED since you need to be sudo to call this command.

Hope that gets you going.
If not, drop back and we can dig into it some more.

1 Like

Beno, I tried the commands you recommended and it seems the device can’t find the pacakage it is connected to the internet via ethernet. I have attached a screenshot to with some redacted info to show you what I see.

Typed Cmds

Please update the repo: sudo apt-get update
Im not sure what firmware version you are running or when the utils were added to the repo…
But yeah, do the update and then try and install them again.

Here is my install after I did the repo update…

opto@lcben:~$ sudo apt-get install ntp-utils
Reading package lists... Done
Building dependency tree... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 146 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1  ntp-utils 4.2.8p4-r0 [146 kB]
Fetched 146 kB in 0s (369 kB/s)
Selecting previously unselected package ntp-utils.
(Reading database ... 96967 files and directories currently installed.)
Preparing to unpack .../ntp-utils_4.2.8p4-r0_armel.deb ...
Unpacking ntp-utils (4.2.8p4-r0) ...
Setting up ntp-utils (4.2.8p4-r0) ...

Thanks, that seemed to work.


Thanks for getting back to the forums. Great to have closure.

I just edited my post to include the apt-get update step… I should not assume that its been done.