宝塔用户_bdiagr 发表于 2021-6-8 16:35:52

【bug提交】centos8.2.2004 计划任务,定期同步服务器时间脚本

本帖最后由 宝塔用户_bdiagr 于 2021-6-8 16:37 编辑

centos 8 已经没有 ntpdate 这个软件了
|-正在尝试从0.pool.bt.cn同步时间
../www/server/cron/99473f50710a29e6c99bcbb61d50e953: line 5: ntpdate: command not found
|-正在尝试将当前系统时间写入硬件..
Fri Jun 22 19:48:40 CST 2018
|-时间同步完成!
----------------------------------------------------------------------------
★ Successful
----------------------------------------------------------------------------



echo "|-正在尝试从0.pool.bt.cn同步时间..";
ntpdate -u 0.pool.bt.cn
if [ $? = 1 ];then
        echo "|-正在尝试从1.pool.bt.cn同步时间..";
        ntpdate -u 1.pool.bt.cn
fi
if [ $? = 1 ];then
        echo "|-正在尝试从0.asia.pool.ntp.org同步时间..";
        ntpdate -u 0.asia.pool.ntp.org
fi
if [ $? = 1 ];then
        echo "|-正在尝试从www.bt.cn同步时间..";
        getBtTime=$(curl -sS --connect-timeout 3 -m 60 http://www.bt.cn/api/index/get_time)
        if [ "${getBtTime}" ];then       
                date -s "$(date -d @$getBtTime +"%Y-%m-%d %H:%M:%S")"
        fi
fi
echo "|-正在尝试将当前系统时间写入硬件..";
hwclock -w
date
echo "|-时间同步完成!";



宝塔用户_bdiagr 发表于 2021-6-8 16:38:46

宝塔版本:7.6.0
页: [1]
查看完整版本: 【bug提交】centos8.2.2004 计划任务,定期同步服务器时间脚本