[ntp:questions] New years glitch?
Terje Mathisen
"terje.mathisen at tmsw.no" at ntp.org
Thu Jan 3 20:04:41 UTC 2013
David Taylor wrote:
> On 02/01/2013 20:34, tylerwalden at gmail.com wrote:
> []
>> David, would it be possible to get the flags your sending to ntpq to
>> check for the leap second flag in your program so we can run them
>> using ntpq on a linux system ? I'd like to setup a monitor for this
>> condition in our environment.
> []
> ========================================================
>
> In essence:
>
> 1: send 'ntpq -c rv <test-server>'
> 2: look for 'leap=01' or 'leap=10'
> 3: leap is pending if either is found
> 4: send 'ntpq -c assoc <test-server>'
> 5: for each assoc-id send: 'ntpq -c "rv <assoc-id>" <test-server>'
> 6: parse the result as in (2) and (3)
>
> I hope that helps, and that I haven't misread my own code! The commands
> are executed on a Windows system. If you come up with the same in a
> script for another OS I could add it to my Web page to help others.
Here's a perl version which should run on any platform with both perl
and ntpq (leap-check.pl):
#!perl -w
use strict;
my $server = shift || die("Usage: leap-check.pl <server>\n");
my $cmd = sprintf('ntpq -c rv %s', $server);
my $rv = `$cmd`;
if (!($rv =~ /[\s,]leap=([01]{2})[\s,\n]/)) { die("No leap info found
from server $server!\n"); }
my $leap = $1;
if ($leap eq '01' || $leap eq '10' || $leap eq '00') {
# Leap bits valid, locate the upstream sources!
printf("%s: %s\n\n", $leap, $server);
$cmd = sprintf('ntpq -c assoc %s', $server);
my $assoc = `$cmd`;
my $ind_to_expect = 1;
foreach (split(/\n/, $assoc)) {
my ($ind, $assid, @fields) = split;
if (defined($ind) && $ind =~ /^\d+$/ && $ind == $ind_to_expect) {
$cmd = sprintf('ntpq -c "rv %s" %s', $assid, $server);
$rv = `$cmd`;
my ($leap, $srcadr) = ('','');
if ($rv =~ /leap=([01]{2})/) {
$leap = $1;
}
if ($rv =~ /srcadr=([^,\s\n]+)[,\s\n]/) {
$srcadr = $1;
}
printf("%s: %s\n", $leap, $srcadr);
$ind_to_expect++;
}
}
}
Terje
--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
More information about the questions
mailing list