#!/bin/bash
[ "`rpm -qa | egrep ^rdate`" ] || yum -y install rdate > /dev/null 2>&1
tz=`date -R | awk ‘{print $NF}‘`
if [ $tz != "+0800" ]
then
\cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo ZONE=\"Asia/Shanghai\" > /etc/sysconfig/clock
fi
/usr/sbin/ntpdate us.ntp.org.cn
if [ $? != 0 ]
then
/usr/bin/rdate -s time.nist.gov
fi
/sbin/hwclock -w
结合cron做成任务计划就可以周期性的自动同步系统时间了
原文地址:http://blog.51cto.com/13719882/2129104