Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / ntp / scripts / ntp-groper
blob1fd0cfe4c2d6ec669e8bc8f469c731fb5d79df23
1 #!/bin/sh
3 # ntpgroper host ...
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
24 verbose=1
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.
31 for host in $*
33 # echo "Trying $host."
35 gethost $host > /dev/null 2>&1
36 if [ $? -ne 0 ]
37 then
38 echo "$host not registered in DNS"
39 continue
42 ping $host 64 1 > /dev/null 2>&1
43 if [ $? -ne 0 ]
44 then
45 echo "$host not responding to ping"
46 continue
49 # Attempt to contact with version 3 ntp, then try version 2.
50 for version in 3 2
53 ntpq -c "ntpversion $version" -p $host > $ntpqlog 2>&1
55 if fgrep -s 'Connection refused' $ntpqlog
56 then
57 echo "$host refused ntpq connection"
58 break
61 responding=1
62 fgrep -s 'timed out, nothing received' $ntpqlog > /dev/null && responding=0
64 if [ $responding -eq 1 ]
65 then
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"
81 break;
84 if [ $version -eq 2 -a $responding -eq 0 ]
85 then
86 echo "$host not responding to NTP"
88 done
89 done
91 # ) >> $logfile
93 if [ -f $ntpqlog ]; then
94 rm $ntpqlog