This is a comprehensive cron reference that covers everything from basic crontab syntax to production-ready job management. You get clear examples of time expressions, special characters, and file locations across different distros. What makes it useful is the practical stuff: a battle-tested script template with locking to prevent duplicate runs, proper logging patterns, and environment variable handling that actually works in cron's stripped-down context. The troubleshooting section addresses the usual pain points like missing PATH variables and permission issues. If you're setting up scheduled tasks beyond trivial one-liners, the examples for database backups, log rotation, and flock-based single instance execution will save you time.
- skills.sh installs
- 1.3K
- GitHub stars
- 59
- last updated
- Aug 21, 2026
Install
$ npx -y skills add chaterm/terminal-skills --skill cron --agent claude-codeInstalls into .claude/skills of the current project.
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
Sponsors
Details
- Repository
- github.com/chaterm/terminal-skills
- Categories
- Automation & Workflows, CLI & Terminal
