温馨提示×

ubuntu定时器怎么停止运行

小樊
39
2026-10-18 17:48:13
栏目: 智能运维

在 Ubuntu 里“定时器”通常指 systemd 的 timer(如 xxx.timer),也可能指 cron 或 at。下面分别说明如何停止。


一、如果是 systemd Timer(最常见)

1️⃣ 查看正在运行的 timer

systemctl list-timers

2️⃣ 停止某个 timer

假设 timer 名是 backup.timer:

sudo systemctl stop backup.timer

3️⃣ 禁止开机启动(彻底停用)

sudo systemctl disable backup.timer

4️⃣ 同时停止并禁用

sudo systemctl disable --now backup.timer

5️⃣ 查看状态

systemctl status backup.timer

二、如果是 cron 定时任务

1️⃣ 编辑当前用户的 cron

crontab -e

2️⃣ 删除或注释对应行

在行前加 #:

# 0 * * * * /home/user/backup.sh

3️⃣ 查看现有 cron

crontab -l

4️⃣ 系统级 cron(/etc/cron.*)

sudo ls /etc/cron.d/
sudo nano /etc/cron.d/xxx

三、如果是 at 定时任务

查看待执行任务

atq

删除任务(假设任务号 3)

atrm 3

四、如果是自己写的脚本循环

如果是后台运行的脚本:

ps aux | grep your_script.sh
kill PID

或:

pkill -f your_script.sh

✅ 推荐做法(systemd 示例)

sudo systemctl disable --now your.timer

如果你能告诉我 具体是哪种定时器(timer 名 / cron / 脚本),我可以给你更精确的命令。

0 踩