centos5.4时间同步shell
2011-11-23 15:55
411 查看
#!/bin/sh
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:
srvlst="ntpserver.lst"
defaultsrv="stdtime.gov.hk"
if [ ! -f "$srvlst" ] ;
then
echo "ntp server file "ntpsrver.lst" not found use default server"
ntpdate $defaultsrv
exit
else
while read srvlst
do
echo $srvlst
ntpdate $srvlst
ret=$?
if [ $ret -eq 0 ] ;
then
echo "ntpdate from $ntpsrv sucessfull !"
exit
fi
done < $srvlst
echo "All ntpserver down,rsync time fail !!!"
exit -1
fi
把以上shell文件保存为ntptime.sh
然后加入crontab即可 ---> vi /etc/crontab
* */2 * * * root sh /etc/ntp/ntptime.sh >/dev/null 2>/dev/null
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:
srvlst="ntpserver.lst"
defaultsrv="stdtime.gov.hk"
if [ ! -f "$srvlst" ] ;
then
echo "ntp server file "ntpsrver.lst" not found use default server"
ntpdate $defaultsrv
exit
else
while read srvlst
do
echo $srvlst
ntpdate $srvlst
ret=$?
if [ $ret -eq 0 ] ;
then
echo "ntpdate from $ntpsrv sucessfull !"
exit
fi
done < $srvlst
echo "All ntpserver down,rsync time fail !!!"
exit -1
fi
把以上shell文件保存为ntptime.sh
然后加入crontab即可 ---> vi /etc/crontab
* */2 * * * root sh /etc/ntp/ntptime.sh >/dev/null 2>/dev/null
相关文章推荐
- centos 安装 ntpdate 并同步时间
- centos下设置时间同步
- CentOS初始化(同步时间,cp忽略,中文乱码)
- CentOS 6 时间,时区,设置修改及时间同步
- CentOS设置系统时间与网络时间同步
- 服务器时间同步 centos
- centos设置时钟同步时间
- CentOS 7 时区调整与时间同步
- CentOS同步网络时间
- CentOS配置时间同步NTP
- CentOS自动同步时间
- 如何快速配置CentOS的时间同步
- centos 修改时区及NTP时间同步
- 同步集群单板时间的shell脚本
- CentOS中时间同步方法
- centos设置时间自动与网络同步
- CentOS 5.4 发现时间显示不正确
- Centos 同步时间
- CentOS 集群自动同步时间的一种方法
- centos网络设置,与授时中心同步时间