4 # This script compares the time of several machines with the
5 # time on the local host.
7 # Use or modify it as you wish.
9 # As the original author is only expecting 14 minutes of fame,
10 # leaving his name attached would be appreciated.
12 # R. Gary Cutbill <rgary@chrysalis.com>
19 open(HOSTS,"ypcat hosts.byaddr |"); # get a list of hosts from the yp server.
21 while ($line=<HOSTS>) { # loop for each host getting the offset compared to localhost
22 ($addr,$host,$aliases)=split(/\s+/,$line,3);
23 $res=`/usr/local/bin/ntptrace -m 1 -r 1 -t 1 $host`;
32 # Sort the list of hosts, and print out there offsets
33 # from the local host.
35 @list=sort appropriately @results;
36 foreach $i ( @list ) {
38 @dargs=split(/\s+/,$i);
39 if ( $dargs[1] eq "\*Timeout\*" ) {
42 push(@down,$dargs[0]);
44 printf "%-25s %7s %3s %6s %10s %5s %8s %8s\n",@dargs;
45 if ( ( $dargs[4] > $tol ) || ( $dargs[4] < -$tol ) ) {
47 push(@toofarout,$dargs[0]); }
51 # When the above list finishes, hosts that are different by +/- $tol (two seconds)
52 # are in @toofarout. Hosts that are down are in @down. They are treated the same
53 # way here, but you might want to do something different depending on your site.
55 # print a set of suggested rsh commands to run on the hosts that
56 # don't have "good" time. "restartntp" is left as an excersize to the reader.
57 # I usually use it to kill a running xntpd, ntpdate some server, and the start xntp
60 print "\nConsider:\n";
61 foreach $i ( (@down,@toofarout) ) {
62 print " rsh $i sudo restartntp\n";
67 # sort the results from the list. First by stratum, then by time deviation
68 # Put hosts that didn't respond (timed out) on the bottom.
73 $aba= ($af[4]<0)?-$af[4]:$af[4];
74 $abb= ($bf[4]<0)?-$bf[4]:$bf[4];
76 ( $af[1] ne $bf[1] ) ? $bf[1] cmp $af[1] :
77 ( ( $af[2] != $bf[2] ) ? ( $bf[2] <=> $af[2] ) :
78 ( ( $aba != $abb ) ? ( $abb <=> $aba ) : ($af[0] cmp $bf[0] ) ) );