Looking for a script to (1) check status of ntp and (2) if it is within +/- 1 second of a given time server (eg 123.456.789.10). (3) In addition, system time should be checked to see if the timezone is set correctly (eg PST)
Here's what I have so far, checking the status of ntp:
#!/bin/bash
if [[ ! -x /usr/bin/ntpstat ]]
then
echo "ntpstat is NOT installed: please install it"
exit 3
res=$(/usr/bin/ntpstat)
rc=$?
case $rc in
0 )
echo "clocks are synchronized"
;;
1 )
echo "WARNING: clocks are NOT synchronized"
;;
2 )
echo "CRITICAL: NTPD IS DOWN -- NO STATUS"
;;
esac
ntpdate -q <known ntp server name/IP>
and parse the output to get the actual offset versus that server. This disconnects the "is it good" logic from the script doing the actual data collection so the script doesn't need to be updated or have a parameter changed if we decide to change how tightly a time sync must be in order to be "good"