build-cron
Original:🇨🇳 Chinese
Translated
Create an OpenClaw cron job that sends a message to the specified channel after execution. Use this skill when the user mentions phrases like "create scheduled task", "new cron", "set scheduled execution", "run periodically", "scheduled task", "every", "every minute", "every hour", "every week", "every month", or "every X hours between A and B". Collect the task name, task description, and execution time (supports four modes: fixed time, interval loop, periodic time, and scheduled range) through conversation, automatically obtain the session key (no user cooperation required), then construct and execute the openclaw cron add command.
19installs
Sourcerinsonlaw/law-skills
Added on
NPX Install
npx skill4agent add rinsonlaw/law-skills build-cronTags
Translated version includes tags in frontmatterSKILL.md Content (Chinese)
View Translation Comparison →Build Cron Skill
Convert user requirements into the command and execute it.
openclaw cron addInstallation Method
bash
npx skills add https://github.com/Rinsonlaw/law-skills.gitWorkflow
Step 1: Collect Information
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.
Step 2: Parse sessionKey (Automatic Retrieval)
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 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
Step 4: Get Time Zone and Construct CLI Command
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
Show the constructed command to the user for confirmation, and execute it after the user inputs .
yesComplete Conversation Examples
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
- 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