Package: sntp
Version: 1:4.2.8p12+dfsg-3
Severity: minor
The sntp documentation explains that, by default, sntp shows the time:
By default, sntp writes the local data and time (i.e., not UTC) to
the standard output in the format:
1996-10-15 20:17:25.123 (+0800) +4.567 +/- 0.089 secs
where YYYY-MM-DD HH:MM:SS.SUBSEC is the local date and time,
(+0800) is the local timezone adjustment (so we would add 8 hours
and 0 minutes to convert the reported local time to UTC), and the
+4.567 +/- 0.089 secs indicates the time offset and error bound of
the system clock relative to the server clock.
That's very useful! In a loop like this, it can serve as a crude
clock, for example:
while sntp pool.ntp.org ; sleep 1; done
Unfortunately, by default the command writes unrelated information to
standard output by default:
$ sntp pool.ntp.org
sntp [email protected] (1)
Can't open KOD db file /var/lib/sntp/kod for writing: Permission denied
2018-09-26 09:41:40.022747 (+0500) -0.297222 +/- 0.724723 pool.ntp.org
144.217.181.221 s2 no-leap
The first line seems to be a version number: I don't think this should
be part of the output at all unless the --version is specified.
The second line is an error documented in a separate bug report
(#865285) so I won't go into details about it here other to say than
the line is written to stdout instead of stderr, which makes it
needless hard to silence. For example, trying the usual `2>/dev/null`
fails:
$ sntp pool.ntp.org 2> /dev/null
sntp [email protected] (1)
Can't open KOD db file /var/lib/sntp/kod for writing: Permission denied
2018-09-26 09:44:25.992889 (+0500) -0.268132 +/- 0.247282 pool.ntp.org
142.93.85.177 s2 no-leap
And obviously, redirecting stdout silences everything, which confirms
those lines are written to stdout:
$ sntp pool.ntp.org > /dev/null
$
This command would be much more useful if it respected those UNIX
standards...
A crude workaround which should work for the next thousand years (give
or take) is:
$ sntp pool.ntp.org | grep ^2
2018-09-26 09:45:46.471668 (+0500) -0.257057 +/- 0.241104 pool.ntp.org
142.93.85.177 s2 no-leap
Thanks!
-- System Information:
Debian Release: buster/sid
APT prefers testing
APT policy: (500, 'testing'), (1, 'experimental'), (1, 'unstable')
Architecture: amd64 (x86_64)
Kernel: Linux 4.18.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=fr_CA.UTF-8, LC_CTYPE=fr_CA.UTF-8 (charmap=UTF-8),
LANGUAGE=fr_CA.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages sntp depends on:
ii libc6 2.27-6
ii libevent-core-2.1-6 2.1.8-stable-4
ii libevent-pthreads-2.1-6 2.1.8-stable-4
ii libopts25 1:5.18.12-4
ii libssl1.1 1.1.0h-4
sntp recommends no packages.
sntp suggests no packages.
-- debconf-show failed