在 Debian 里“定时器”通常指 systemd timer(用来替代 cron),也可能是 cron/anacron。下面分别说明。
假设服务叫 myjob:
服务文件
/etc/systemd/system/myjob.service
[Unit]
Description=My Job
[Service]
Type=oneshot
ExecStart=/usr/local/bin/myjob.sh
定时器文件
/etc/systemd/system/myjob.timer
[Unit]
Description=Run My Job Daily
[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true
[Install]
WantedBy=timers.target
sudo systemctl daemon-reload
sudo systemctl enable --now myjob.timer
systemctl status myjob.timer
systemctl list-timers
sudo systemctl start myjob.service
crontab -e
0 2 * * * /usr/local/bin/myjob.sh
系统级任务可放
/etc/cron.d/或/etc/crontab
Type=oneshot 适合脚本任务Persistent=true 可补跑错过的任务.timer,不是 .servicedaemon-reload如果你说的“定时器”是指 具体某个服务(如 apt、fail2ban、nginx),可以告诉我服务名,我给你具体命令。