New advertisers: 50% off your first month with code FIRSTMONTHSee slots

Practical crontab guide covering schedule syntax, system and per-user config files, safe script templates, logging, and troubleshooting.

skills.sh installs
1.3K
GitHub stars
60
last updated
Aug 21, 2026
View on GitHub

What it does

  • Covers crontab management with crontab -e, -l, -r, and -u, plus schedule syntax and special strings like @daily and @reboot
  • Includes config locations for user crontabs, /etc/crontab, /etc/cron.d, and the hourly, daily, weekly, and monthly directories
  • Provides a script template with a lock file to block duplicate runs and flock for single-instance jobs
  • Designed for server administrators scheduling backups, log rotation, and health checks on Debian or RHEL systems

Install

$ npx -y skills add chaterm/terminal-skills --skill cron -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

定时任务管理

概述

Cron 定时任务配置、日志监控、故障排查等技能。

Crontab 基础

管理命令

# 编辑当前用户的 crontab
crontab -e

# 查看当前用户的 crontab
crontab -l

# 删除当前用户的 crontab
crontab -r

# 管理其他用户的 crontab(需要 root)
crontab -u username -e
crontab -u username -l

时间格式

┌───────────── 分钟 (0-59)
│ ┌───────────── 小时 (0-23)
│ │ ┌───────────── 日 (1-31)
│ │ │ ┌───────────── 月 (1-12)
│ │ │ │ ┌───────────── 星期 (0-7, 0和7都是周日)
│ │ │ │ │
* * * * * command

特殊字符

*       # 任意值
,       # 列表 (1,3,5)
-       # 范围 (1-5)
/       # 步长 (*/5 每5分钟)

# 示例
0 * * * *       # 每小时整点
*/15 * * * *    # 每15分钟
0 9-17 * * *    # 9点到17点每小时
0 0 * * 1-5     # 工作日零点
0 0 1,15 * *    # 每月1号和15号零点

特殊时间字符串

@reboot         # 系统启动时
@yearly         # 每年 (0 0 1 1 *)
@monthly        # 每月 (0 0 1 * *)
@weekly         # 每周 (0 0 * * 0)
@daily          # 每天 (0 0 * * *)
@hourly         # 每小时 (0 * * * *)

配置文件

用户 crontab

# 位置
/var/spool/cron/crontabs/username   # Debian/Ubuntu
/var/spool/cron/username            # CentOS/RHEL

# 格式
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
MAILTO=admin@example.com

# 任务
0 2 * * * /usr/local/bin/backup.sh

Details

Repository
github.com/chaterm/terminal-skills
Categories
CLI & Terminal, DevOps & Cloud

More from chaterm/terminal-skills

All 5

Similar to Cron

More CLI & Terminal