1 1.1 christos #!/bin/sh 2 1.1 christos # 3 1.1 christos # ntpgroper host ... 4 1.1 christos # 5 1.1 christos # This script checks each hostname given as an argument to see if 6 1.1 christos # it is running NTP. It reports one of the following messages (assume 7 1.1 christos # the host is named "dumbo.hp.com": 8 1.1 christos # 9 1.1 christos # dumbo.hp.com not registered in DNS 10 1.1 christos # dumbo.hp.com not responding to ping 11 1.1 christos # dumbo.hp.com refused ntpq connection 12 1.1 christos # dumbo.hp.com not responding to NTP 13 1.1 christos # dumbo.hp.com answers NTP version 2, stratum: 3, ref: telford.nsa.hp.com 14 1.1 christos # dumbo.hp.com answers NTP version 3, stratum: 3, ref: telford.nsa.hp.com 15 1.1 christos # 16 1.1 christos # It ain't pretty, but it is kinda useful. 17 1.1 christos # 18 1.1 christos # Walter Underwood, 11 Feb 1993, wunder (at] hpl.hp.com 19 1.1 christos # 20 1.1 christos # converted to /bin/sh from /bin/ksh by scott (at] ee.udel.edu 24 Mar 1993 21 1.1 christos 22 1.1 christos PATH="/usr/local/etc:$PATH" export PATH 23 1.1 christos 24 1.1 christos verbose=1 25 1.1 christos logfile=/tmp/cntp-log$$ 26 1.1 christos ntpqlog=/tmp/cntp-ntpq$$ 27 1.1 christos 28 1.1 christos # I wrap the whole thing in parens so that it is possible to redirect 29 1.1 christos # all the output somewhere, if desired. 30 1.1 christos ( 31 1.1 christos for host in $* 32 1.1 christos do 33 1.1 christos # echo "Trying $host." 34 1.1 christos 35 1.1 christos gethost $host > /dev/null 2>&1 36 1.1 christos if [ $? -ne 0 ] 37 1.1 christos then 38 1.1 christos echo "$host not registered in DNS" 39 1.1 christos continue 40 1.1 christos fi 41 1.1 christos 42 1.1 christos ping $host 64 1 > /dev/null 2>&1 43 1.1 christos if [ $? -ne 0 ] 44 1.1 christos then 45 1.1 christos echo "$host not responding to ping" 46 1.1 christos continue 47 1.1 christos fi 48 1.1 christos 49 1.1 christos # Attempt to contact with version 3 ntp, then try version 2. 50 1.1 christos for version in 3 2 51 1.1 christos do 52 1.1 christos 53 1.1 christos ntpq -c "ntpversion $version" -p $host > $ntpqlog 2>&1 54 1.1 christos 55 1.1 christos if fgrep -s 'Connection refused' $ntpqlog 56 1.1 christos then 57 1.1 christos echo "$host refused ntpq connection" 58 1.1 christos break 59 1.1 christos fi 60 1.1 christos 61 1.1 christos responding=1 62 1.1 christos fgrep -s 'timed out, nothing received' $ntpqlog > /dev/null && responding=0 63 1.1 christos 64 1.1 christos if [ $responding -eq 1 ] 65 1.1 christos then 66 1.1 christos ntpq -c "ntpversion $version" -c rl $host > $ntpqlog 67 1.1 christos 68 1.1 christos # First we extract the reference ID (usually a host or a clock) 69 1.1 christos synchost=`fgrep "refid=" $ntpqlog` 70 1.1 christos #synchost=${synchost##*refid=} # strip off the beginning of the line 71 1.1 christos #synchost=${synchost%%,*} # strip off the end 72 1.1 christos synchost=`expr "$synchost" : '.*refid=\([^,]*\),.*'` 73 1.1 christos 74 1.1 christos # Next, we get the stratum 75 1.1 christos stratum=`fgrep "stratum=" $ntpqlog` 76 1.1 christos #stratum=${stratum##*stratum=} 77 1.1 christos #stratum=${stratum%%,*} 78 1.1 christos stratum=`expr "$stratum" : '.*stratum=\([^,]*\),.*'` 79 1.1 christos 80 1.1 christos echo "$host answers NTP version $version, stratum: $stratum, ref: $synchost" 81 1.1 christos break; 82 1.1 christos fi 83 1.1 christos 84 1.1 christos if [ $version -eq 2 -a $responding -eq 0 ] 85 1.1 christos then 86 1.1 christos echo "$host not responding to NTP" 87 1.1 christos fi 88 1.1 christos done 89 1.1 christos done 90 1.1 christos ) 91 1.1 christos # ) >> $logfile 92 1.1 christos 93 1.1 christos if [ -f $ntpqlog ]; then 94 1.1 christos rm $ntpqlog 95 1.1 christos fi 96