Debian 里“定时器失败”通常指 systemd timer 没有按预期触发,或者 cron / at 任务没执行。下面按常见原因系统说明,你可以对照排查。
systemctl list-timers
systemctl status yourtimer.timer
如果没启用:
systemctl enable --now yourtimer.timer
timer 只负责“触发”,真正执行的是 .service:
systemctl status yourservice.service
journalctl -u yourservice.service
常见错误:
示例:
OnCalendar=*-*-* 02:00:00
错误写法会导致 timer 永不触发。
检查:
systemd-analyze calendar "你的时间表达式"
timedatectl
NTP 未同步会导致 timer 行为异常:
timedatectl set-ntp true
timer 在关机期间不会补执行(除非 Persistent=true):
[Timer]
Persistent=true
systemctl status cron
没运行就:
systemctl enable --now cron
cron 环境非常干净,常见失败:
~✅ 建议写法:
0 2 * * * /usr/bin/python3 /opt/script.py >> /var/log/script.log 2>&1
/etc/cron.d/ 文件权限必须是 644cron.allowsystemctl status atd
atq
atd 没启动会导致任务不执行。
journalctl -xe
systemctl list-timers --all
systemctl status cron
date
如果你能贴出:
我可以直接帮你定位是哪一步错了。