#/bin/bash #update time #author swh function ntpdcheck(){ netstat -tunlp | grep ntpd ret=$? if [ $ret -eq 0 ] then echo "Need kill ntpd " killall ntpd -9 chkconfig ntpd off elif [ $ret -eq 1 ] then echo "ntpd has be killed! It is ok" else echo "test ntpd errot ,please check" fi } read -p "Do you want to check ntpd,please input yes or no:" y case $Y in "yes") ntpdcheck; ntpdcheck; ;; "no") echo "ntpdcheck is cancel" ;; *) esac echo -n "Now check ntpdate install or not install:" rpm -qa | grep ntpdate ret=$? if [ $ret -eq 0 ] then echo "ntpdate is installed" elif [ $ret -eq 1 ] then echo "ntpdate is installing:" yum -y install ntpdate else echo "ntpdate install failed! please check" fi echo "*/5 * * * * /usr/sbin/ntpdate cn.pool.ntp.org" >> /var/spool/cron/root echo -e "now crontab is :\n" crontab -l
说明:该脚本非常臃肿,很久以前练习shell脚本的时候写的,实际意义不大。实际一个语句就完成了:
echo “*/5 * * * * /usr/sbin/ntpdate cn.pool.ntp.org” >> /var/spool/cron/root
推荐授时中心地址
cn.pool.ntp.org 常用
210.72.145.44 国家授时中心服务器
亚洲地区的ntp服务器一览表
Bangladesh — bd.pool.ntp.org (0)
China — cn.pool.ntp.org (3)
Hong Kong — hk.pool.ntp.org (1)
India — in.pool.ntp.org (2)
Indonesia — id.pool.ntp.org (2)
Iran — ir.pool.ntp.org (0)
Israel — il.pool.ntp.org (3)
Japan — jp.pool.ntp.org (5)
Korea — kr.pool.ntp.org (4)
Malaysia — my.pool.ntp.org (3)
Philippines — ph.pool.ntp.org (0)
Singapore — sg.pool.ntp.org (3)
Taiwan — tw.pool.ntp.org (7)
Thailand — th.pool.ntp.org (1)
Turkey — tr.pool.ntp.org (1)
United Arab Emirates — ae.pool.ntp.org (0)
国外授时中心服务器:
time.nist.gov
time-a.nist.gov
time-b.nist.gov
time-nw.nist.gov
转载请注明:西数超哥博客www.ysidc.top» [原创]linux 自动同步时间脚本以及常用授时中心地址
https://www.ysidc.top 西数超哥博客,数据库,西数超哥,虚拟主机,域名注册,域名,云服务器,云主机,云建站,ysidc.top