/contrib/ntp/scripts/checktime.in

https://bitbucket.org/freebsd/freebsd-head/ · Autoconf · 79 lines · 39 code · 8 blank · 32 comment · 7 complexity · 27ca12e1bcdeaad33f67132da6ca965f MD5 · raw file

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