温馨提示×

debian定时器怎么暂停

小樊
73
2026-09-20 03:27:00
栏目: 智能运维

在 Debian(以及大多数 Linux 发行版)里,“定时器”通常指的是 systemd timer(系统定时器)。下面按常见需求说明如何暂停/停止/临时禁用定时器。


一、暂停(停止)一个正在运行的 systemd 定时器

sudo systemctl stop your-timer.timer

这只会立即停止,但重启后可能还会自动启动。


二、禁止开机自启(彻底暂停)

sudo systemctl disable your-timer.timer

如果你想立即停止 + 禁止开机启动:

sudo systemctl disable --now your-timer.timer

三、临时“屏蔽”定时器(最强力暂停)

sudo systemctl mask your-timer.timer

效果:

  • 定时器无法启动
  • 即使被其他服务依赖也无法运行
  • 恢复需要 unmask

恢复:

sudo systemctl unmask your-timer.timer

四、查看定时器状态

systemctl list-timers
systemctl status your-timer.timer

五、如果你指的是 cron(不是 systemd timer)

暂停某个 cron 任务

编辑 crontab:

crontab -e

在对应行前加 #:

# 0 * * * * /path/script.sh

暂停所有 cron

sudo systemctl stop cron
sudo systemctl disable cron

六、常见场景建议

需求 推荐命令
临时停一下 systemctl stop xxx.timer
不希望开机运行 systemctl disable --now xxx.timer
完全锁死 systemctl mask xxx.timer
不确定是不是 systemd systemctl list-timers

如果你能告诉我:

  • 是 systemd timer 还是 cron
  • 定时器名字(或路径)

我可以给你更精确的一条命令。

0 踩