自动化实战:`cron` + `hooks` + `tasks`
约 1 分钟
1) cron:让任务按时跑
一句话:cron 负责“什么时候做”。
一次性任务示例:
openclaw cron add \
--name "Reminder" \
--at "2026-02-01T16:00:00Z" \
--session main \
--system-event "Reminder: check docs" \
--wake now \
--delete-after-run查看与强制执行:
openclaw cron list
openclaw cron run <job-id> --force
openclaw cron runs --id <job-id>周期任务示例:
openclaw cron add \
--name "Morning brief" \
--cron "0 7 * * *" \
--tz "Asia/Shanghai" \
--session isolated \
--message "Summarize overnight updates." \
--announce2) hooks:让事件触发动作
一句话:hooks 负责“发生什么就做什么”。
常用命令:
openclaw hooks list
openclaw hooks enable session-memory
openclaw hooks check
openclaw hooks info session-memory内置 hook 例子:
session-memory:/new时保存上下文。command-logger:记录命令日志。
3) tasks:后台任务追踪
一句话:tasks 是“任务账本”,不是调度器。
常用命令(文档示例):
openclaw tasks listopenclaw tasks show <lookup>openclaw tasks cancel <lookup>
4) 三者关系(必须理解)
cron:定义何时触发。hooks:定义事件触发。tasks:记录后台运行发生了什么。
5) 推荐自动化闭环模板
cron每天 8:00 触发。- 调用一个 Skill 抓信息并整理。
- 结果投递到指定渠道。
- 失败时通过
tasks或日志追踪。
练习任务
- 做一个“每天早上 8 点日报”。
- 加一个 hook:
/new时自动备份会话摘要。 - 故意制造一次失败,学会用 tasks/logs 定位。