Files
deploy.stack/crontab/timeUpdate.job
cnphpbb 2ec24b6dc0 chore: 修改文件权限从可执行变为不可执行
将crontab和n9e目录下的部分文件权限从755修改为644,移除可执行权限
2025-11-25 17:08:42 +08:00

38 lines
1021 B
Bash

#!/usr/bin/env bash
## crontab -e
## 0 1 * * * /home/geng/mydate/deploy.stack/crontab/timeUpdate.job >> /dev/null 2>&1
# 时间同步更新任务
# 尝试使用 ntpdate 更新时间
try_ntpdate() {
if command -v ntpdate &> /dev/null; then
echo "$(date): 使用 ntpdate 同步时间"
ntpdate -u cn.pool.ntp.org || ntpdate -u ntp.aliyun.com
return $?
fi
return 1
}
# 尝试使用 timedatectl 更新时间
try_timedatectl() {
if command -v timedatectl &> /dev/null; then
echo "$(date): 使用 timedatectl 同步时间"
timedatectl set-ntp true
return $?
fi
return 1
}
# 执行时间同步
if try_ntpdate; then
echo "$(date): 时间同步成功 (ntpdate)"
elif try_timedatectl; then
echo "$(date): 时间同步成功 (timedatectl)"
else
echo "$(date): 时间同步失败,未找到可用的时间同步工具"
exit 1
fi
# 可选:保存同步日志
echo "$(date): 系统时间已更新为: $(date)" >> /var/log/timeUpdate.log 2>&1