build-cron
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBuild Cron Skill
Build Cron Skill
将用户需求转换为 命令并执行。
openclaw cron addConvert user requirements into the command and execute it.
openclaw cron add安装方法
Installation Method
bash
npx skills add https://github.com/Rinsonlaw/law-skills.gitbash
npx skills add https://github.com/Rinsonlaw/law-skills.git工作流程
Workflow
第一步:收集信息
Step 1: Collect Information
向用户询问以下信息(不要跳跃,等用户回复后再继续):
- 任务名称 — 用户给这个定时任务起的名字,如
daily-report - 任务描述 — 用户说的原话,直接填入 (不要总结,不要改写)
--message - 执行时间 — 用户期望的执行时间,支持四种模式:
- 定点时间:询问小时(0-23)和分钟(0-59),如"20 30"表示晚上8点30分
- 间隔循环:询问间隔数值和单位,如"每5分钟"、"每2小时"
- 周期时间:指定每周几或每月几号,如"每周一9点"、"每月1号0点"
- 小时范围:指定在哪些小时执行,如"10点到12点每隔1小时"
Session Key 自动获取:自动从当前会话的元数据中获取,不需要用户手动提供。
Ask the user for the following information (do not skip steps; proceed only after the user replies):
- Task Name — The name given by the user for this cron job, e.g.,
daily-report - Task Description — The user's exact words, directly fill into (do not summarize or rewrite)
--message - Execution Time — The user's desired execution time, supporting four modes:
- Fixed Time: Ask for hour (0-23) and minute (0-59), e.g., "20 30" means 8:30 PM
- Interval Loop: Ask for the interval value and unit, e.g., "every 5 minutes", "every 2 hours"
- Periodic Time: Specify a day of the week or day of the month, e.g., "9 AM every Monday", "12 AM on the 1st of every month"
- Hourly Range: Specify which hours to execute, e.g., "every 1 hour between 10 AM and 12 PM"
Automatic Session Key Retrieval: Automatically obtained from the current session's metadata; no manual input required from the user.
第二步:解析 sessionKey(自动获取)
Step 2: Parse sessionKey (Automatic Retrieval)
自动从当前会话元数据中获取 sessionKey,不需要用户配合。然后用冒号 分割,提取以下字段:
:session_key = "agent:research:feishu:direct:ou_xxx"
agent_id = session_key_parts[1] # → "research"
channel_name = session_key_parts[2] # → "feishu"
target_id = session_key_parts[4] # → "ou_xxx"Automatically retrieve the sessionKey from the current session metadata without user cooperation. Then split it with a colon to extract the following fields:
:session_key = "agent:research:feishu:direct:ou_xxx"
agent_id = session_key_parts[1] # → "research"
channel_name = session_key_parts[2] # → "feishu"
target_id = session_key_parts[4] # → "ou_xxx"第三步:解析执行时间
Step 3: Parse Execution Time
cron 表达式格式说明(从左到右):
| 位置 | 代表含义 | 取值范围 |
|---|---|---|
| 第1个 | 分钟 | 0-59, |
| 第2个 | 小时 | 0-23, |
| 第3个 | 日期 | 1-31 |
| 第4个 | 月份 | 1-12 |
| 第5个 | 星期 | 0-6(0=周日) |
范围语法:
-
— 每任意值
* -
— 指定值
A -
— 范围,适用于任意位置,如
A-B(小时)、10-12(日期)、5-31(星期)2-5 -
— 间隔,如
*/N表示每5个单位*/5 -
— 范围间隔,如
A-B/N表示从10到12每间隔110-12/1 -
示例:每 5 分钟 →(第1个位置为
"*/5 * * * *")*/5 -
示例:每 2 小时 →(第2个位置为
"0 */2 * * *")*/2 -
示例:每小时 →
"0 * * * *" -
示例:每周一早上9点 →
"0 9 * * 1" -
示例:每月1号凌晨0点 →
"0 0 1 * *" -
示例:10点到12点每1小时 →
"0 10-12/1 * * *" -
示例:工作日9点到18点每2小时 →
"0 9-18/2 * * 1-5"
执行时间支持四种模式:
模式 A:定点时间
- 用户说"每天早上8点"、"晚上8点30分"等
- 需要解析出小时(0-23)和分钟(0-59)
- 生成 cron 表达式:
{minute} {hour} * * * - 示例:小时=8, 分钟=0 →
"0 8 * * *"
模式 B:间隔循环
- 用户说"每隔5分钟"、"每30分钟"、"每小时"等
- 需要解析出间隔数值和单位(分钟/小时)
- 间隔循环的 cron 表达式格式:(每 N 分钟)或
*/{interval} * * * *(每 N 小时)0 */{interval} * * *
模式 C:周期时间
- 用户说"每周一9点"、"每月1号凌晨0点"等
- 需要解析出:周期类型(周/月)、具体日期(周一/1号)、小时和分钟
- 生成 cron 表达式:
{minute} {hour} {day_of_month} {month} {day_of_week} - 星期:0=周日,1=周一,...,6=周六
- 示例:每周一早上9点 →
"0 9 * * 1" - 示例:每月1号凌晨0点 →
"0 0 1 * *"
模式 D:定时范围
- 用户说"10点到12点每隔1小时"、"工作日早上9点到下午6点每隔2小时"等
- 需要解析出:起始时间、结束时间、执行间隔
- cron 表达式格式:
{minute} {start_hour}-{end_hour}/{interval} * * - 示例:10点到12点每隔1小时,0分执行 →
"0 10-12/1 * * *" - 示例:9点到18点每隔2小时 →
"0 9-18/2 * * *" - 注意:范围通常指小时范围,间隔单位为小时
判断规则:
- 如果用户提到"每隔"、"每.*分钟"、"每.*小时",则视为间隔循环模式
- 如果用户提到"每周"、"每月"、"周几",则视为周期时间模式
- 如果用户提到"点到点每隔",则视为定时范围模式
- 如果用户只说时间点(如"8点"、"20:30"),则视为定点时间模式
Cron expression format explanation (left to right):
| Position | Meaning | Value Range |
|---|---|---|
| 1st | Minute | 0-59, |
| 2nd | Hour | 0-23, |
| 3rd | Day of Month | 1-31 |
| 4th | Month | 1-12 |
| 5th | Day of Week | 0-6 (0=Sunday) |
Range Syntax:
-
— Any value
* -
— Specified value
A -
— Range, applicable to any position, e.g.,
A-B(hours),10-12(days),5-31(weekdays)2-5 -
— Interval, e.g.,
*/Nmeans every 5 units*/5 -
— Range with interval, e.g.,
A-B/Nmeans every 1 unit from 10 to 1210-12/1 -
Example: Every 5 minutes →(1st position is
"*/5 * * * *")*/5 -
Example: Every 2 hours →(2nd position is
"0 */2 * * *")*/2 -
Example: Every hour →
"0 * * * *" -
Example: 9 AM every Monday →
"0 9 * * 1" -
Example: 12 AM on the 1st of every month →
"0 0 1 * *" -
Example: Every 1 hour between 10 AM and 12 PM →
"0 10-12/1 * * *" -
Example: Every 2 hours between 9 AM and 6 PM on workdays →
"0 9-18/2 * * 1-5"
Execution time supports four modes:
Mode A: Fixed Time
- User says "8 AM every day", "8:30 PM", etc.
- Need to parse hour (0-23) and minute (0-59)
- Generate cron expression:
{minute} {hour} * * * - Example: hour=8, minute=0 →
"0 8 * * *"
Mode B: Interval Loop
- User says "every 5 minutes", "every 30 minutes", "every hour", etc.
- Need to parse interval value and unit (minute/hour)
- Cron expression format for interval loop: (every N minutes) or
*/{interval} * * * *(every N hours)0 */{interval} * * *
Mode C: Periodic Time
- User says "9 AM every Monday", "12 AM on the 1st of every month", etc.
- Need to parse: period type (week/month), specific date (Monday/1st), hour and minute
- Generate cron expression:
{minute} {hour} {day_of_month} {month} {day_of_week} - Day of week: 0=Sunday, 1=Monday, ..., 6=Saturday
- Example: 9 AM every Monday →
"0 9 * * 1" - Example: 12 AM on the 1st of every month →
"0 0 1 * *"
Mode D: Scheduled Range
- User says "every 1 hour between 10 AM and 12 PM", "every 2 hours between 9 AM and 6 PM on workdays", etc.
- Need to parse: start time, end time, execution interval
- Cron expression format:
{minute} {start_hour}-{end_hour}/{interval} * * * - Example: Every 1 hour between 10 AM and 12 PM, execute at 0 minutes →
"0 10-12/1 * * *" - Example: Every 2 hours between 9 AM and 6 PM →
"0 9-18/2 * * *" - Note: The range usually refers to hourly range, and the interval unit is hours
Judgment Rules:
- If the user mentions "every", "every * minutes", "every * hours", it is considered Interval Loop mode
- If the user mentions "every week", "every month", "day of week", it is considered Periodic Time mode
- If the user mentions "every X hours between A and B", it is considered Scheduled Range mode
- If the user only mentions a time point (e.g., "8 AM", "20:30"), it is considered Fixed Time mode
第四步:获取时区并构造 CLI 命令
Step 4: Get Time Zone and Construct CLI Command
使用以下参数构造 命令:
openclaw cron addbash
TZ=$(readlink /etc/localtime | sed 's|.*zoneinfo/||')
openclaw cron add \
--name "{task_name}" \
--agent "{agent_id}" \
--session-key "{session_key}" \
--cron "{cron_expr}" \
--tz "$TZ" \
--session "isolated" \
--wake "now" \
--message "{task_message}" \
--timeout-seconds 600 \
--announce \
--channel "{channel_name}" \
--to "{target_id}"参数说明:
| CLI 参数 | 说明 | 默认值 |
|---|---|---|
| 任务名称 | 必填 |
| 从 sessionKey 解析 | 必填 |
| 完整 session key | 必填 |
| cron 表达式 | 必填 |
| 时区 | 自动检测 |
| session 模式 | |
| 唤醒模式 | |
| 任务描述(用户的原话,不做任何修改) | 必填 |
| 超时秒数 | |
| 启用结果播报到 channel | 默认关闭 |
| 播报 channel | 从 sessionKey 解析 |
| 播报目标 | 从 sessionKey 解析 |
注意:时区固定为,若用户需要其他时区可替换。"Asia/Shanghai"
Construct the command using the following parameters:
openclaw cron addbash
TZ=$(readlink /etc/localtime | sed 's|.*zoneinfo/||')
openclaw cron add \
--name "{task_name}" \
--agent "{agent_id}" \
--session-key "{session_key}" \
--cron "{cron_expr}" \
--tz "$TZ" \
--session "isolated" \
--wake "now" \
--message "{task_message}" \
--timeout-seconds 600 \
--announce \
--channel "{channel_name}" \
--to "{target_id}"Parameter Explanation:
| CLI Parameter | Description | Default Value |
|---|---|---|
| Task name | Required |
| Parsed from sessionKey | Required |
| Complete session key | Required |
| Cron expression | Required |
| Time zone | Automatically detected via |
| Session mode | |
| Wake-up mode | |
| Task description (user's exact words, no modifications) | Required |
| Timeout in seconds | |
| Enable result announcement to channel | Disabled by default |
| Announcement channel | Parsed from sessionKey |
| Announcement target | Parsed from sessionKey |
Note: The time zone is fixed to; users can replace it if other time zones are needed."Asia/Shanghai"
第五步:执行创建命令
Step 5: Execute the Creation Command
将构造好的命令展示给用户确认,用户输入 后执行。
yesShow the constructed command to the user for confirmation, and execute it after the user inputs .
yes完整对话示例
Complete Conversation Examples
定点时间示例:
用户:我想创建一个定时任务,每天晚上8点执行
助手:请问这个任务叫什么名字?
用户:nightly-digest
助手:请问这个任务具体要做什么?(直接填入 message,原话即可)
用户:每晚整理并总结当天的竞品动态
助手:请问执行时间是几点几分?(比如 20 30 表示晚上8点30分)
用户:20 30
助手:(自动获取当前 session key)
识别为定点时间模式,构造如下命令,请确认是否创建:
TZ=$(readlink /etc/localtime | sed 's|.*zoneinfo/||')
openclaw cron add \
--name "nightly-digest" \
--agent "research" \
--session-key "agent:research:feishu:direct:ou_xxx" \
--cron "30 20 * * *" \
--tz "$TZ" \
--session "isolated" \
--wake "now" \
--message "每晚整理并总结当天的竞品动态" \
--timeout-seconds 600 \
--announce \
--channel "feishu" \
--to "ou_xxx"
是否确认创建?(输入 yes 确认)
用户:yes
助手:执行命令...间隔循环示例:
用户:我想每5分钟检查一下服务器状态
助手:请问这个任务叫什么名字?
用户:server-health-check
助手:请问这个任务具体要做什么?(直接填入 message,原话即可)
用户:检查服务器状态是否正常
助手:请问执行时间是怎样的?(比如 "每5分钟" 或 "每2小时")
用户:每5分钟
助手:(自动获取当前 session key)
识别为间隔循环模式(每5分钟),构造如下命令,请确认是否创建:
TZ=$(readlink /etc/localtime | sed 's|.*zoneinfo/||')
openclaw cron add \
--name "server-health-check" \
--agent "research" \
--session-key "agent:research:feishu:direct:ou_xxx" \
--cron "*/5 * * * *" \
--tz "$TZ" \
--session "isolated" \
--wake "now" \
--message "检查服务器状态是否正常" \
--timeout-seconds 600 \
--announce \
--channel "feishu" \
--to "ou_xxx"
是否确认创建?(输入 yes 确认)
用户:yes
助手:执行命令...Fixed Time Example:
User: I want to create a scheduled task that runs every day at 8 PM
Assistant: What is the name of this task?
User: nightly-digest
Assistant: What does this task specifically do? (Please provide the exact words to fill into message)
User: Compile and summarize the day's competitor dynamics every night
Assistant: What is the execution time in hour and minute? (e.g., 20 30 means 8:30 PM)
User: 20 30
Assistant: (Automatically retrieves current session key)
Identified as Fixed Time mode, constructed the following command. Please confirm creation:
TZ=$(readlink /etc/localtime | sed 's|.*zoneinfo/||')
openclaw cron add \
--name "nightly-digest" \
--agent "research" \
--session-key "agent:research:feishu:direct:ou_xxx" \
--cron "30 20 * * *" \
--tz "$TZ" \
--session "isolated" \
--wake "now" \
--message "Compile and summarize the day's competitor dynamics every night" \
--timeout-seconds 600 \
--announce \
--channel "feishu" \
--to "ou_xxx"
Confirm creation? (Enter yes to confirm)
User: yes
Assistant: Executing command...Interval Loop Example:
User: I want to check server status every 5 minutes
Assistant: What is the name of this task?
User: server-health-check
Assistant: What does this task specifically do? (Please provide the exact words to fill into message)
User: Check if the server status is normal
Assistant: What is the execution time pattern? (e.g., "every 5 minutes" or "every 2 hours")
User: every 5 minutes
Assistant: (Automatically retrieves current session key)
Identified as Interval Loop mode (every 5 minutes), constructed the following command. Please confirm creation:
TZ=$(readlink /etc/localtime | sed 's|.*zoneinfo/||')
openclaw cron add \
--name "server-health-check" \
--agent "research" \
--session-key "agent:research:feishu:direct:ou_xxx" \
--cron "*/5 * * * *" \
--tz "$TZ" \
--session "isolated" \
--wake "now" \
--message "Check if the server status is normal" \
--timeout-seconds 600 \
--announce \
--channel "feishu" \
--to "ou_xxx"
Confirm creation? (Enter yes to confirm)
User: yes
Assistant: Executing command...注意事项
Notes
- 必须等待用户回复再继续下一步,不要假设用户提供的信息
- 如果自动获取 session key 失败,记录错误并告知用户
- 所有固定值参数已在命令模板中写死,不需要用户输入
- 命令生成后必须得到用户确认才能执行
- Must wait for user replies before proceeding to the next step; do not assume information provided by the user
- If automatic session key retrieval fails, record the error and inform the user
- All fixed-value parameters are pre-written in the command template; no user input required
- The generated command must be confirmed by the user before execution