自动化与定时任务
Cron 是 OpenClaw 内置的调度器,支持定时任务和提醒。
Cron vs Heartbeat
| 特性 | Cron | Heartbeat |
|---|---|---|
| 触发方式 | 时间调度 | 定期唤醒 |
| 适用场景 | 定时任务 | 持续监控 |
| 会话隔离 | 独立会话 | 主会话 |
创建定时任务
方式一:一次性提醒
openclaw cron add \
--name "会议提醒" \
--at "2026-03-01T14:00:00Z" \
--session main \
--system-event "提醒:下午2点开会" \
--wake now \
--delete-after-run
方式二:重复任务
# 每天早上 7 点发送摘要
openclaw cron add \
--name "早间摘要" \
--cron "0 7 * * *" \
--tz "Asia/Shanghai" \
--session isolated \
--message "总结今天的日程和待办事项" \
--deliver \
--channel whatsapp \
--to "+861xxxxxxxxx"
方式三:定期监控
# 每小时检查服务器状态
openclaw cron add \
--name "服务器检查" \
--every "1h" \
--session isolated \
--message "检查服务器状态,如有异常立即报告"
Cron 高级配置
隔离会话任务
openclaw cron add \
--name "每日报告" \
--cron "0 18 * * *" \
--tz "Asia/Shanghai" \
--session isolated \
--message "生成今日工作报告" \
--model "opus" \
--thinking high \
--deliver \
--channel telegram
Agent 选择(多 Agent 设置)
# 将任务绑定到特定 Agent
openclaw cron add \
--name "数据分析" \
--cron "0 9 * * 1" \
--session isolated \
--message "分析本周数据" \
--agent analytics
Cron 管理命令
# 列出所有任务
openclaw cron list
# 查看任务详情
openclaw cron status
# 编辑任务
openclaw cron edit <jobId> \
--message "更新的提示文本"
# 手动运行任务
openclaw cron run <jobId> --force
# 启用/禁用任务
openclaw cron enable <jobId>
openclaw cron disable <jobId>
# 删除任务
openclaw cron rm <jobId>
# 查看运行历史
openclaw cron runs --id <jobId> --limit 50
Cron 表达式
┌───────────── 分钟 (0 - 59)
│ ┌─────────── 小时 (0 - 23)
│ │ ┌───────── 日期 (1 - 31)
│ │ │ ┌─────── 月份 (1 - 12)
│ │ │ │ ┌───── 星期 (0 - 6,0 = 周日)
│ │ │ │ │
* * * * *
常用示例:
| 表达式 | 含义 |
|---|---|
| 0 7 * * * | 每天 7:00 |
| 0 */2 * * * | 每 2 小时 |
| 0 0 * * 1 | 每周一 00:00 |
| 0 9,18 * * * | 每天 9:00 和 18:00 |
| 0 0 1 * * | 每月 1 号 00:00 |
相关文章: