红联Linux门户
Linux帮助

基于NTP的多服务器时间同步脚本

发布时间:2015-04-13 21:32:11来源:linux网站作者:Javame

server服务器每1个小时更新一次时间,server服务器旗下同步服务器每5秒钟同步一次时间,同步服务器与外网不做交互,由server服务器进行同步时间。所以保证每一台同步服务器时间一致。


#vi ud_ntp.sh

#!/bin/bash
time=5
ip(){
echo "192.168.48.114"
echo "192.168.28.233"
}
stp(){
/etc/init.d/ntpd stop
}
upd(){
ntpdate us.pool.ntp.org
}
stt(){
/etc/init.d/ntpd start
}

num=`ps -ef | grep ntpd.pid | grep -v grep`
not(){
if [ ! -n "$num" ]; then
#      echo "IS NULL"
upd
stt
else
#      echo "NOT NULL"
stp
upd
stt
fi
}

ntp(){
while true
do
sleep $time
for i in `ip`
do
ssh $i ntpdate 192.168.48.117
if [[ 00 == `date | awk -F ":" '{print $2}'` ]]
then
not
sleep 240
break
fi
done
done
}
ntp&


还有什么考虑不周全的地方,大家指正!