5 # This script checks each hostname given as an argument to see if
6 # it is running NTP. It reports one of the following messages (assume
7 # the host is named "dumbo.hp.com":
9 # dumbo.hp.com not registered in DNS
10 # dumbo.hp.com not responding to ping
11 # dumbo.hp.com refused ntpq connection
12 # dumbo.hp.com not responding to NTP
13 # dumbo.hp.com answers NTP version 2, stratum: 3, ref: telford.nsa.hp.com
14 # dumbo.hp.com answers NTP version 3, stratum: 3, ref: telford.nsa.hp.com
16 # It ain't pretty, but it is kinda useful.
18 # Walter Underwood, 11 Feb 1993, wunder@hpl.hp.com
20 # converted to /bin/sh from /bin/ksh by scott@ee.udel.edu 24 Mar 1993
22 PATH
="/usr/local/etc:$PATH" export PATH
25 logfile
=/tmp
/cntp-log$$
26 ntpqlog
=/tmp
/cntp-ntpq$$
28 # I wrap the whole thing in parens so that it is possible to redirect
29 # all the output somewhere, if desired.
33 # echo "Trying $host."
35 gethost
$host > /dev
/null
2>&1
38 echo "$host not registered in DNS"
42 ping $host 64 1 > /dev
/null
2>&1
45 echo "$host not responding to ping"
49 # Attempt to contact with version 3 ntp, then try version 2.
53 ntpq
-c "ntpversion $version" -p $host > $ntpqlog 2>&1
55 if fgrep
-s 'Connection refused' $ntpqlog
57 echo "$host refused ntpq connection"
62 fgrep
-s 'timed out, nothing received' $ntpqlog > /dev
/null
&& responding
=0
64 if [ $responding -eq 1 ]
66 ntpq
-c "ntpversion $version" -c rl
$host > $ntpqlog
68 # First we extract the reference ID (usually a host or a clock)
69 synchost
=`fgrep "refid=" $ntpqlog`
70 #synchost=${synchost##*refid=} # strip off the beginning of the line
71 #synchost=${synchost%%,*} # strip off the end
72 synchost
=`expr "$synchost" : '.*refid=\([^,]*\),.*'`
74 # Next, we get the stratum
75 stratum
=`fgrep "stratum=" $ntpqlog`
76 #stratum=${stratum##*stratum=}
77 #stratum=${stratum%%,*}
78 stratum
=`expr "$stratum" : '.*stratum=\([^,]*\),.*'`
80 echo "$host answers NTP version $version, stratum: $stratum, ref: $synchost"
84 if [ $version -eq 2 -a $responding -eq 0 ]
86 echo "$host not responding to NTP"
93 if [ -f $ntpqlog ]; then