ntp时间校验

ntp时间校验

#!/bin/bash
# Author: royoy
# Date: Aug 01/2015
# Desc: ntpdate time sync

# NTP服务器数组列表
ntpServer=(
[0]=tw.pool.ntp.org
[1]=time.stdtime.gov.tw
[2]=asia.pool.ntp.org
[3]=10.10.10.5
)

#校验#
serverNum=`echo ${#ntpServer[*]}`
NUM=0
for ((i=0; i<=$serverNum; i++)); do
    echo -n "正在和NTP服务器:${ntpServer[$NUM]}校验中..." >>/var/log/ntp.log
    /usr/sbin/ntpdate ${ntpServer[$NUM]} >> /dev/null 2>&1
    if [ $? -eq 0 ]; then
        echo -e "\e[1;32m\t[成功]\e[0m"  >>/var/log/ntp.log
        echo -e "\e[1;32m同步成功,退出......\e[0m" >>/var/log/ntp.log
        break
    else
        echo -e "\e[1;31m\t[失败]\e[0m" >>/var/log/ntp.log
        echo -e "\e[1;31m继续同步下一个!!!!!\e[0m" >>/var/log/ntp.log
        let NUM++
    fi
    sleep 2
done