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
#!/bin/bash ## Output nothing if sync eventually works ## Output an error if unsuccessful after $MAX_RETRIES TIMESERVER="time.nist.gov" MAX_RETRIES="3" RETRIES=0 while [[ $RC != 0 && $RETRIES -lt $MAX_RETRIES ]] do /usr/bin/rdate -s $TIMESERVER RC=$? 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" fi