温馨提示×

debian定时器怎样查看状态

小樊
50
2026-09-14 00:19:57
栏目: 智能运维

在 Debian(以及大多数使用 systemd 的现代 Linux 发行版)中,“定时器”通常指 systemd timer(对应 .timer 单元)。下面按常见需求说明如何查看状态。


一、查看所有定时器状态

systemctl list-timers

常用参数:

systemctl list-timers --all      # 包括未激活的
systemctl list-timers --no-pager # 不分页

输出示例字段说明:

  • NEXT:下次执行时间
  • LEFT:距离下次执行剩余时间
  • LAST:上次执行时间
  • PASSED:距上次执行已过时间
  • UNIT:对应的 service 单元

二、查看某个定时器的状态

systemctl status xxx.timer

例如:

systemctl status apt-daily.timer

可看到:

  • 是否启用(enabled / disabled)
  • 是否活跃(active / inactive)
  • 上次 / 下次触发时间

三、查看定时器是否启用

systemctl is-enabled xxx.timer

输出:

  • enabled
  • disabled
  • static
  • masked

四、查看定时器是否正在运行(活跃)

systemctl is-active xxx.timer

输出:

  • active
  • inactive
  • failed

五、查看定时器对应的服务执行情况

定时器通常会触发一个 .service:

systemctl status xxx.service
journalctl -u xxx.service

查看某定时器最近日志:

journalctl -u xxx.timer
journalctl -u xxx.service

六、传统 cron(非 systemd timer)

如果你指的是 cron 定时任务:

查看当前用户的 cron

crontab -l

查看系统级 cron

ls -l /etc/cron.*
cat /etc/crontab

查看 cron 服务状态

systemctl status cron

七、快速排查建议

如果定时器“没生效”:

  1. 是否 enabled
    systemctl enable xxx.timer
    
  2. 是否 active
    systemctl start xxx.timer
    
  3. 看日志
    journalctl -u xxx.timer -u xxx.service
    

如果你能告诉我:

  • 是 systemd timer 还是 cron
  • 定时器名称(如 xxx.timer)

我可以给你更具体的命令和排查步骤。

0 踩