centos5.4時間同步shell

#!/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 &gt;/dev/null 2&gt;/dev/null

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章