您的位置:首页 > 编程语言 > PHP开发

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

2015-04-13 10:34 519 查看
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&


还有什么考虑不周全的地方,大家指正!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: