技术咨询
1377-5048-177
宝塔计划任务增加一条Shell脚本
脚本代码如下:
echo "|-检查ntpdate命令是否就绪.." is_ntpdate=$(which ntpdate) if [ "$is_ntpdate" = "" ];then if [ -f /usr/bin/apt ];then apt install ntpdate -y else is_dnf=$(which dnf) if [ "$is_dnf" = "" ];then yum install ntpdate -y fi fi fi is_ntpdate=$(which ntpdate) is_http=0 if [ "$is_ntpdate" != "" ];then echo "|-正在尝试从1.pool.bt.cn同步时间.."; ntpdate -u 1.pool.bt.cn if [ $? = 1 ];then echo "|-正在尝试从0.asia.pool.ntp.org同步时间.."; ntpdate -u 0.asia.pool.ntp.org fi else is_http=1 fi if [ $? = 1 ] || [ $is_http = 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 echo "|-设置时间: "$(date -s "$(date -d @$getBtTime +"%Y-%m-%d %H:%M:%S")") fi fi echo "|-正在尝试将当前系统时间写入硬件.."; hwclock -w echo "|-当前时间为:$(date)" echo "|-时间同步完成!";
上一篇:我是有底线的