/[cricket]/parse_ntpq.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /parse_ntpq.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Thu Nov 7 08:33:30 2002 UTC (21 years, 4 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -1 lines
File MIME type: text/plain
better usage

1 dpavlin 1.1 #!/usr/bin/perl -w
2    
3     # Based on work of Matthew.Stier@fnc.fujitsu.com
4 dpavlin 1.2 #
5     # Dobrica Pavlinusic <dpavlin@rot13.org>
6     # http://www.rot13.org/~dpavlin/sysadm.html
7     #
8     # Usage: parse_ntpq.pl host peer
9 dpavlin 1.1
10     use strict;
11    
12     my $gInstallRoot;
13     BEGIN {
14     $gInstallRoot = (($0 =~ m:^(.*/):)[0] || "./") . "..";
15     }
16    
17    
18     use lib "$gInstallRoot/lib";
19     use strict;
20    
21     # Test for the number of arguments
22     if ($#ARGV != 1) {
23 dpavlin 1.3 print STDERR "usage: $0 host [peer|--config]\n";
24 dpavlin 1.1 exit 1;
25     }
26    
27     # Get the server
28     my($server) = shift @ARGV;
29     # Get the peer
30     my($peer) = shift @ARGV;
31    
32     my @targets;
33    
34     # Get the ntpq data
35     open(NTPQ,"/usr/bin/ntpq -pn $server |") || die "ntpq: $!";
36    
37     if ($peer eq "--config") {
38     print "target --default--\n\tserver = $server\n\n";
39     }
40    
41     my $skip_header = 1;
42     # Step through remaining lines
43     while (<NTPQ>) {
44     chomp;
45     next if (! /^=+$/ && $skip_header);
46     $skip_header = 0;
47    
48     # Break lines into fields
49     my($remote, $refid, $stratum, $t, $when, $poll, $reach,
50     $delay, $offset, $jitter) = (split ' ', substr($_, 1), 10);
51     # Print delay, offset, and jitter
52     print "$delay\n$offset\n$jitter\n" if ( $remote eq $peer );
53     if ($peer eq "--config" && $reach && $reach > 0 && $remote ne "127.127.1.1") {
54     print "target $server-$remote\n\tpeer = $remote\n\tskip-overview = 1\n\n";
55     push @targets,"$server-$remote";
56     }
57     }
58    
59     if ($peer eq "--config") {
60     print "target $server-overview\n\tmtargets = \"",join("; ",@targets),"\"";
61     }

  ViewVC Help
Powered by ViewVC 1.1.26