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

你可能感兴趣的:(server,File,local,Export,default)