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

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

#vi ud_ntp.sh

#!/bin/bash
time=
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 [[ == `date | awk -F ":" '{print $2}'` ]]
then
not
sleep
break
fi
done
done
}
ntp&

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

上一篇:基2时域抽取FFT、IFFT的C++实现代码,另附DFT与IDFT的原始实现--转1


下一篇:#6 Python数据类型及运算