/contrib/ntp/scripts/ntp-status

https://bitbucket.org/freebsd/freebsd-head/ · Shell · 45 lines · 32 code · 9 blank · 4 comment · 4 complexity · e3df40cbd877929e901799d9fba2f39a MD5 · raw file

  1. #!/bin/sh
  2. # From: Marc Brett <Marc.Brett@westgeo.com>
  3. # Here's a quick hack which can give you the stratum, delay, offset
  4. # for any number of ntp servers.
  5. NTPDATE=/usr/local/bin/ntpdate
  6. NSLOOKUP=/usr/sbin/nslookup
  7. EGREP=/bin/egrep
  8. AWK=/bin/awk
  9. RM=/bin/rm
  10. FILE=/tmp/ntp.$$
  11. USAGE="Usage: $0 hostname [hostname ...]"
  12. if [ $# -le 0 ]
  13. then
  14. echo $USAGE 2>&1
  15. exit 1
  16. fi
  17. trap '$RM -f $FILE; exit' 1 2 3 4 13 15
  18. for HOST in $*
  19. do
  20. HOSTNAME=`$NSLOOKUP $HOST | $EGREP "Name:" | $AWK '{print $2}'`
  21. if [ -n "$HOSTNAME" ]
  22. then
  23. $NTPDATE -d $HOST 2>/dev/null | $EGREP '^stratum|^delay|^offset|^originate' > $FILE
  24. STRATUM=`$EGREP '^stratum' $FILE | $AWK '{print $2}'`
  25. OFFSET=`$EGREP '^offset' $FILE | $AWK '{print $2}'`
  26. DELAY=`$EGREP '^delay' $FILE | $AWK '{print $2}'`
  27. TIMESTAMP=`$EGREP '^originate' $FILE | $AWK '{print $4 " " $5 " " $6 " " $7 " " $8}'`
  28. if [ "$STRATUM" -ne 0 ]
  29. then
  30. echo "$HOSTNAME: stratum:$STRATUM delay:$DELAY offset:$OFFSET $TIMESTAMP"
  31. else
  32. echo $HOSTNAME: Not running NTP
  33. fi
  34. fi
  35. done
  36. $RM -f $FILE