命令概述
openclaw cron 命令用于管理 OpenClaw 的定时任务系统。你可以设置定时发送消息、周期性执行 AI 任务或触发自动化工作流。
查看定时任务
openclaw cron list
Cron Jobs:
ID Schedule Channel Status Description
──────────────────────────────────────────────────────────────────
daily-news 0 8 * * * telegram-main Active 每日新闻摘要
weekly-rpt 0 9 * * 1 slack-team Active 周报生成
health-chk */5 * * * * - Active 系统健康检查
birthday 0 10 * * * telegram-main Active 生日提醒
创建定时任务
交互式创建
openclaw cron add
命令行创建
# 每天早上8点发送新闻摘要
openclaw cron add daily-news \
--schedule "0 8 * * *" \
--channel telegram-main \
--prompt "请搜索今天的科技新闻,生成一份简短的中文摘要" \
--tools web_search
# 每周一早上9点生成周报
openclaw cron add weekly-report \
--schedule "0 9 * * 1" \
--channel slack-team \
--prompt "汇总本周的项目进展,生成一份周报" \
--model gpt-4o
# 每5分钟检查系统健康
openclaw cron add health-monitor \
--schedule "*/5 * * * *" \
--action health-check \
--notify-on-failure telegram-admin
Cron 表达式
┌───────────── 分钟 (0-59)
│ ┌───────────── 小时 (0-23)
│ │ ┌───────────── 日 (1-31)
│ │ │ ┌───────────── 月 (1-12)
│ │ │ │ ┌───────────── 星期 (0-7, 0和7都是周日)
│ │ │ │ │
* * * * *
常用表达式:
| 表达式 | 含义 |
|---|---|
0 8 * * * |
每天8:00 |
0 */2 * * * |
每2小时 |
0 9 * * 1 |
每周一9:00 |
0 0 1 * * |
每月1号0:00 |
*/5 * * * * |
每5分钟 |
0 8,12,18 * * * |
每天8/12/18点 |
也支持简写:
openclaw cron add task --schedule "@daily" # 每天0:00
openclaw cron add task --schedule "@hourly" # 每小时
openclaw cron add task --schedule "@weekly" # 每周日0:00
任务类型
AI 消息任务
让 AI 生成并发送消息:
openclaw cron add morning-greeting \
--schedule "0 8 * * *" \
--channel telegram-main \
--prompt "用友好的方式问候大家早安,可以加入一句名人名言"
系统任务
执行系统维护操作:
# 定期清理过期会话
openclaw cron add cleanup \
--schedule "0 3 * * *" \
--action sessions-cleanup \
--args "--older-than 7d"
# 定期备份
openclaw cron add backup \
--schedule "0 2 * * *" \
--action backup \
--args "--output /backups/"
Webhook 触发任务
定时调用外部 API:
openclaw cron add api-check \
--schedule "*/10 * * * *" \
--action webhook \
--url "https://api.example.com/status" \
--notify-on-failure telegram-admin
管理任务
# 暂停任务
openclaw cron pause daily-news
# 恢复任务
openclaw cron resume daily-news
# 立即执行一次
openclaw cron run daily-news
# 修改调度
openclaw cron update daily-news --schedule "0 9 * * *"
# 删除任务
openclaw cron delete old-task
查看执行日志
openclaw cron logs daily-news
openclaw cron logs daily-news --last 10
Execution Log: daily-news
[2026-03-18 08:00:01] ✓ Completed (2.5s) - Message sent
[2026-03-17 08:00:01] ✓ Completed (3.1s) - Message sent
[2026-03-16 08:00:02] ✗ Failed - Provider timeout
[2026-03-15 08:00:01] ✓ Completed (1.8s) - Message sent
时区设置
# 设置全局时区
openclaw cron set-timezone "Asia/Shanghai"
# 为特定任务设置时区
openclaw cron update daily-news --timezone "America/New_York"
总结
openclaw cron 让 AI 助手不再只是被动响应,而是可以主动执行定期任务。从每日新闻推送到系统维护,定时任务大大扩展了 OpenClaw 的自动化能力。