Rhel 7
Rhel 7
/bin/bash
# time-offset_check.sh
#
# Checks computer clock against specified NTP server. Issues a warning
# on stdout, if the time difference exceeds limit. Requires ntpdate, bc
# and egrep in path. Run from cron as often as you like.
### Options
DATE=`date +%Y%m%d`
LOGFILE=/var/log/ntpstats/time_sync_${DATE}
if [[ `ps -ef | grep ntpd | grep -v grep | wc -l` -eq 0 ]]; then
systemctl start ntpd
fi
OLD_OFFSET=`ntpdate -q $NTPSERVER \
| egrep -o -m 1 -e "offset ((-)?[0-9]+\.[0-9]+)" \
| egrep -o -e "[0-9]+\.[0-9]+"`
NEW_OFFSET=`ntpdate -q $NTPSERVER \
| egrep -o -m 1 -e "offset ((-)?[0-9]+\.[0-9]+)" \
| egrep -o -e "[0-9]+\.[0-9]+"`
fi
ntpstat | {
while read line; do
done
}
exit 0