rdate synchronization problems

A bunch of the servers I manage have started having a problem with their daily time sync. Whenever rdate fails, it prints an error message to STDOUT. Since all of the servers are running the sync via cron.daily, this generates a bunch of emails to me, and doesn’t attempt to sync the time for another day.

As a result, I’ve written a simple wrapper for rdate that retries it several times and only prints an error if it was unsuccessful after all of those.

Here is the script. This was written for a CentOS server, so the program paths may need to be changed if you are running it on another distro


## Output nothing if sync eventually works
## Output an error if unsuccessful after $MAX_RETRIES


while [[ $RC != 0 && $RETRIES -lt $MAX_RETRIES ]]
/usr/bin/rdate -s $TIMESERVER
RETRIES=`/usr/bin/expr $RETRIES + 1`
done > /dev/null 2>&1

if [[ $RC != 0 ]]; then
echo "Error syncing time to $TIMESERVER after $MAX_RETRIES tries"
echo "Last RC was $RC"

Leave a Reply

Your email address will not be published. Required fields are marked *