Webpipe Internet Solutions
  Webpipe Internet Services   Webpipe Internet Services   Webpipe Internet Services   Webpipe Internet Services   Webpipe Internet Services
Home Company Info Internet Service Hosting Services Support
Discussion and support Forums   Website Hosting   Wireless, DSL, and Dial-up internet access   Affiliate Login

Sync time

From Webpipe Wiki

If you have your own Red-Hat based (including CentOS) server, it's useful to synchronize the time on your server to a recognized source. The time server at time.nist.gov is the run by the US Federal Government's National Institute of Standards and Technology and is available for public use. You can synchronize to it by running the command:

rdate -s time.nist.gov


To have your server automatically synchronize the time each day, simply add a script that does this to /etc/cron.daily

/etc/cron.daily/sync_time contents:
/usr/bin/rdate -s time.nist.gov > /dev/null 2>&1


Sometimes the rdate command above fails. This simple script can be used instead. It will try several times to synchronize the time and only display an error of all of them failed.:

#!/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
Views