#!/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