xref: /freebsd/contrib/ntp/scripts/deprecated/ntp-status (revision 416ba5c74546f32a993436a99516d35008e9f384)
1*2b15cb3dSCy Schubert#!/bin/sh
2*2b15cb3dSCy Schubert
3*2b15cb3dSCy Schubert# From: Marc Brett <Marc.Brett@westgeo.com>
4*2b15cb3dSCy Schubert
5*2b15cb3dSCy Schubert# Here's a quick hack which can give you the stratum, delay, offset
6*2b15cb3dSCy Schubert# for any number of ntp servers.
7*2b15cb3dSCy Schubert
8*2b15cb3dSCy SchubertNTPDATE=/usr/local/bin/ntpdate
9*2b15cb3dSCy SchubertNSLOOKUP=/usr/sbin/nslookup
10*2b15cb3dSCy SchubertEGREP=/bin/egrep
11*2b15cb3dSCy SchubertAWK=/bin/awk
12*2b15cb3dSCy SchubertRM=/bin/rm
13*2b15cb3dSCy SchubertFILE=/tmp/ntp.$$
14*2b15cb3dSCy Schubert
15*2b15cb3dSCy SchubertUSAGE="Usage: $0 hostname [hostname ...]"
16*2b15cb3dSCy Schubert
17*2b15cb3dSCy Schubertif [ $# -le 0 ]
18*2b15cb3dSCy Schubertthen
19*2b15cb3dSCy Schubert	echo $USAGE 2>&1
20*2b15cb3dSCy Schubert	exit 1
21*2b15cb3dSCy Schubertfi
22*2b15cb3dSCy Schubert
23*2b15cb3dSCy Schuberttrap '$RM -f $FILE; exit' 1 2 3 4 13 15
24*2b15cb3dSCy Schubert
25*2b15cb3dSCy Schubertfor HOST in $*
26*2b15cb3dSCy Schubertdo
27*2b15cb3dSCy Schubert    HOSTNAME=`$NSLOOKUP $HOST | $EGREP "Name:" | $AWK '{print $2}'`
28*2b15cb3dSCy Schubert    if [ -n "$HOSTNAME" ]
29*2b15cb3dSCy Schubert    then
30*2b15cb3dSCy Schubert	$NTPDATE -d $HOST 2>/dev/null | $EGREP '^stratum|^delay|^offset|^originate' > $FILE
31*2b15cb3dSCy Schubert	STRATUM=`$EGREP '^stratum' $FILE | $AWK '{print $2}'`
32*2b15cb3dSCy Schubert	OFFSET=`$EGREP '^offset' $FILE | $AWK '{print $2}'`
33*2b15cb3dSCy Schubert	DELAY=`$EGREP '^delay' $FILE | $AWK '{print $2}'`
34*2b15cb3dSCy Schubert	TIMESTAMP=`$EGREP '^originate' $FILE | $AWK '{print $4 " " $5 " " $6 " " $7 " " $8}'`
35*2b15cb3dSCy Schubert	if [ "$STRATUM" -ne 0 ]
36*2b15cb3dSCy Schubert	then
37*2b15cb3dSCy Schubert		echo "$HOSTNAME: stratum:$STRATUM delay:$DELAY offset:$OFFSET  $TIMESTAMP"
38*2b15cb3dSCy Schubert	else
39*2b15cb3dSCy Schubert		echo $HOSTNAME: Not running NTP
40*2b15cb3dSCy Schubert	fi
41*2b15cb3dSCy Schubert    fi
42*2b15cb3dSCy Schubert
43*2b15cb3dSCy Schubertdone
44*2b15cb3dSCy Schubert
45*2b15cb3dSCy Schubert$RM -f $FILE
46