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
Added on

NPX Install

npx skill4agent add rinsonlaw/law-skills build-cron

Tags

Translated version includes tags in frontmatter

SKILL.md Content (Chinese)

View Translation Comparison →

Build Cron Skill

Convert user requirements into the
openclaw cron add
command and execute it.

Installation Method

bash
npx skills add https://github.com/Rinsonlaw/law-skills.git

Workflow

Step 1: Collect Information

Ask the user for the following information (do not skip steps; proceed only after the user replies):
  1. Task Name — The name given by the user for this cron job, e.g.,
    daily-report
  2. Task Description — The user's exact words, directly fill into
    --message
    (do not summarize or rewrite)
  3. 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):
PositionMeaningValue Range
1stMinute0-59,
*/N
means every N minutes
2ndHour0-23,
*/N
means every N hours
3rdDay of Month1-31
4thMonth1-12
5thDay of Week0-6 (0=Sunday)
Range Syntax:
  • *
    — Any value
  • A
    — Specified value
  • A-B
    — Range, applicable to any position, e.g.,
    10-12
    (hours),
    5-31
    (days),
    2-5
    (weekdays)
  • */N
    — Interval, e.g.,
    */5
    means every 5 units
  • A-B/N
    — Range with interval, e.g.,
    10-12/1
    means every 1 unit from 10 to 12
  • Example: Every 5 minutes →
    "*/5 * * * *"
    (1st position is
    */5
    )
  • Example: Every 2 hours →
    "0 */2 * * *"
    (2nd position is
    */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:
    */{interval} * * * *
    (every N minutes) or
    0 */{interval} * * *
    (every N hours)
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
openclaw cron add
command using the following parameters:
bash
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 ParameterDescriptionDefault Value
--name
Task nameRequired
--agent
Parsed from sessionKeyRequired
--session-key
Complete session keyRequired
--cron
Cron expressionRequired
--tz
Time zoneAutomatically detected via
readlink /etc/localtime
--session
Session mode
"isolated"
--wake
Wake-up mode
"now"
--message
Task description (user's exact words, no modifications)Required
--timeout-seconds
Timeout in seconds
600
--announce
Enable result announcement to channelDisabled by default
--channel
Announcement channelParsed from sessionKey
--to
Announcement targetParsed from sessionKey
Note: The time zone is fixed to
"Asia/Shanghai"
; users can replace it if other time zones are needed.

Step 5: Execute the Creation Command

Show the constructed command to the user for confirmation, and execute it after the user inputs
yes
.

Complete 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