Here's my solution:
I don't want the time checking more often than once a day (I do not want to annoy those timeservers!)
I put this line in root's crontab
Code:
5 * * * * /usr/sbin/chktime
So the script
chktime is called at five minutes past every hour.
This is the script, it is very simple:
Code:
#!/bin/bash
# chktime
# No need to check the time more than once a day, no matter how often
# this script is called
# Note the date format: we do NOT want spaces in the date!
NOW=`date +%a%b%d`
LAST=`cat /etc/.lasttimecheck`
if [ "$NOW" != "$LAST" ]; then
echo -n $NOW > /etc/.lasttimecheck
/usr/sbin/ntpdate uk.pool.ntp.org ; echo "ntpdate set the date" >> /var/log/messages
fi