您的位置:首页 > 运维架构 > Shell

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: