在 Debian(及大多数 Linux 发行版)里,“定时器”通常指 systemd timer(最常见),也可能是 cron。下面分别说调试方法。
systemctl list-timers
systemctl list-timers --all
查看某个定时器:
systemctl status mytimer.timer
systemctl cat mytimer.timer
sudo systemctl start mytimer.service
或:
sudo systemctl trigger mytimer.timer
journalctl -u mytimer.service -f
journalctl -u mytimer.timer -f
sudo SYSTEMD_LOG_LEVEL=debug systemctl start mytimer.timer
或临时改 service:
[Service]
Environment=SYSTEMD_LOG_LEVEL=debug
systemd-analyze calendar "*-*-* 03:00:00"
systemd-analyze timestamp "now"
.timer 里没写 WantedBy=timers.targetsystemctl enableOnCalendar 写错格式Type=oneshot 没写sudo journalctl -u cron -f
或:
grep cron /var/log/syslog
/bin/bash -x /path/to/script.sh
cron 环境极少:
* * * * * export PATH=/usr/local/bin:/usr/bin:/bin; /path/script.sh
* * * * * /path/script.sh >> /tmp/cron.log 2>&1
✅ timer 是否已 enable
✅ service 是否可手动运行
✅ journalctl 是否有报错
✅ 路径是否绝对路径
✅ 用户权限是否正确
如果你愿意,可以把 你的 timer / cron 配置 发出来,我可以直接帮你定位问题。