#!/bin/bash ntp_server="clock.redhat.com" drift_log="./drift.log" error() { echo "Error: $1" exit 1 } [[ `which ntpdate` ]] || error "cannot find ntpdate" [[ -f /var/lock/subsys/ntpd ]] && /etc/init.d/ntpd stop [[ -f /var/run/chronyd.pid ]] && /etc/init.d/chrony stop ntpdate $ntp_server || error "unable to contact NTP server $ntp_server" /sbin/hwclock while true do out=`ntpdate -q $ntp_server | grep ntpdate` time=`echo $out | awk '{print $3}'` skew=`echo $out | awk '{print $10}' | awk -F. '{print $1}'` echo "$time $skew seconds" echo "$time $skew seconds" >> $drift_log sleep 60 done