openclaw cron
管理 Agent 的定时任务(Cron Jobs),支持按计划自动触发 Agent 执行指定指令。
命令签名
bash
openclaw cron <子命令> [选项]子命令
| 子命令 | 说明 |
|---|---|
add | 添加新的定时任务 |
list | 列出所有定时任务 |
edit | 编辑已有的定时任务 |
run | 手动触发执行一次 |
runs | 查看任务执行历史 |
remove | 删除定时任务 |
openclaw cron add
创建一个新的定时任务。
bash
openclaw cron add [选项]| 选项 | 类型 | 说明 |
|---|---|---|
--name <name> | string | 任务名称(必填) |
--cron <expr> | string | Cron 表达式(必填) |
--message <prompt> | string | 发送给 Agent 的指令(必填) |
--agent <name> | string | 指定执行的 Agent(默认 default) |
--enabled | boolean | 创建后立即启用(默认 true) |
openclaw cron list
列出所有已配置的定时任务。
bash
openclaw cron list [--json]输出示例:
ID NAME CRON NEXT RUN STATUS
cron_001 日报生成 0 7 * * * 2024-01-15 07:00 enabled
cron_002 数据清理 0 2 * * 0 2024-01-21 02:00 enabled
cron_003 周报汇总 0 9 * * 1 2024-01-22 09:00 disabledopenclaw cron edit
编辑已有的定时任务。
bash
openclaw cron edit --id <id> [选项]支持与 add 相同的选项来修改对应字段。
openclaw cron run
手动触发一次定时任务(不影响定时计划)。
bash
openclaw cron run --id <id>openclaw cron runs
查看指定任务的执行历史记录。
bash
openclaw cron runs --id <id> [选项]| 选项 | 类型 | 说明 |
|---|---|---|
--limit <n> | number | 显示最近 N 条记录(默认 10) |
--json | boolean | JSON 格式输出 |
openclaw cron remove
删除指定的定时任务。
bash
openclaw cron remove --id <id> [--force]示例
bash
# 添加每天早上 7 点执行的任务
openclaw cron add --name "日报生成" --cron "0 7 * * *" --message "生成今日工作日报"
# 添加每周一上午 9 点的周报任务
openclaw cron add --name "周报汇总" --cron "0 9 * * 1" --message "汇总本周数据并生成周报"
# 查看所有任务
openclaw cron list
# 手动触发一次
openclaw cron run --id cron_001
# 查看执行历史
openclaw cron runs --id cron_001 --limit 5
# 删除任务
openclaw cron remove --id cron_003Cron 表达式参考
┌────────── 分钟 (0-59)
│ ┌──────── 小时 (0-23)
│ │ ┌────── 日 (1-31)
│ │ │ ┌──── 月 (1-12)
│ │ │ │ ┌── 星期 (0-7, 0和7=周日)
│ │ │ │ │
* * * * *| 表达式 | 说明 |
|---|---|
0 7 * * * | 每天早上 7:00 |
*/30 * * * * | 每 30 分钟 |
0 9 * * 1 | 每周一 9:00 |
0 2 * * 0 | 每周日凌晨 2:00 |
另请参阅
openclaw agent— Agent 管理openclaw hooks— 事件钩子管理openclaw config— 配置管理
