/cron Command

The /cron command provides tools to work with cron expressions. Cron is a time-based job scheduler used in Unix-like operating systems, and cron expressions are used to define when automated tasks should run.

Discord syntax: /cron <subcommand> <options>

Available Subcommands

The Discord version uses slash command with subcommands:
• /cron explain expression: <cron_expression>
• /cron nextrun expression: <cron_expression> [count: <number>]
• /cron generate [minute: <value>] [hour: <value>] [day: <value>] [month: <value>] [weekday: <value>]
• /cron common [name: <expression_name>]

Explain a Cron Expression

Explains a cron expression in human-readable form.

/cron explain expression: <cron_expression>

Options

OptionDescriptionRequired
expressionThe cron expression to explain (e.g., ‘0 0 * * *‘)Yes

Example

/cron explain expression: 0 0 * * 1-5

Output

**Cron Expression: `0 0 * * 1-5`**

This cron expression will run at minute 0, at midnight, every day, every month, from Monday to Friday.

Calculate Next Executions

Calculates the next executions of a cron expression.

/cron nextrun expression: <cron_expression> [count: <number>]

Options

OptionDescriptionRequired
expressionThe cron expression (e.g., ‘0 0 * * *‘)Yes
countNumber of executions to show (default: 5, max: 10)No

Example

/cron nextrun expression: 0 0 * * * count: 3

Output

**Next 3 executions for cron expression: `0 0 * * *`**

1. Monday, 11 March 2024 00:00 (`Mon, 11 Mar 2024 00:00:00 UTC`)
2. Tuesday, 12 March 2024 00:00 (`Tue, 12 Mar 2024 00:00:00 UTC`)
3. Wednesday, 13 March 2024 00:00 (`Wed, 13 Mar 2024 00:00:00 UTC`)

Generate a Cron Expression

Generates a cron expression from individual fields.

/cron generate [minute: <value>] [hour: <value>] [day: <value>] [month: <value>] [weekday: <value>]

Options

OptionDescriptionRequired
minuteMinute field (0-59, *, */5, etc.)No
hourHour field (0-23, *, */2, etc.)No
dayDay of month field (1-31, *, etc.)No
monthMonth field (1-12, *, etc.)No
weekdayDay of week field (0-6, *, etc., where 0=Sunday)No

Example

/cron generate minute: 0 hour: 9 weekday: 1-5

Output

**Generated Cron Expression: `0 9 * * 1-5`**

**Explanation:**
This cron expression will run at minute 0, at hour 9, every day, every month, from Monday to Friday.

**Next 3 executions:**
1. Monday, 11 March 2024 09:00 (`Mon, 11 Mar 2024 09:00:00 UTC`)
2. Tuesday, 12 March 2024 09:00 (`Tue, 12 Mar 2024 09:00:00 UTC`)
3. Wednesday, 13 March 2024 09:00 (`Wed, 13 Mar 2024 09:00:00 UTC`)

Show Common Cron Expressions

Shows common cron expressions or details about a specific common expression.

/cron common [name: <expression_name>]

Options

OptionDescriptionRequired
nameName of the common expressionNo

Example 1 (list all common expressions)

/cron common

Output 1

**Common Cron Expressions**

• `Every Minute`: `* * * * *`
• `Every Hour`: `0 * * * *`
• `Every Day At Midnight`: `0 0 * * *`
• `Every Day At Noon`: `0 12 * * *`
• `Every Weekday`: `0 0 * * 1-5`
• `Every Weekend`: `0 0 * * 0,6`
• `Every Month`: `0 0 1 * *`
• `Every Quarter`: `0 0 1 1,4,7,10 *`
• `Every Six Months`: `0 0 1 1,7 *`
• `Every Year`: `0 0 1 1 *`
• `Every Monday`: `0 0 * * 1`
• `Every Friday`: `0 0 * * 5`
• `Every Sunday`: `0 0 * * 0`

Use `/cron common name:expression_name` to get details about a specific expression.

Example 2 (specific common expression)

/cron common name: every_weekday

Output 2

**Common Cron Expression: `every_weekday`**
**Expression:** `0 0 * * 1-5`

**Explanation:**
This cron expression will run at minute 0, at midnight, every day, every month, from Monday to Friday.

**Next 3 executions:**
1. Monday, 11 March 2024 00:00 (`Mon, 11 Mar 2024 00:00:00 UTC`)
2. Tuesday, 12 March 2024 00:00 (`Tue, 12 Mar 2024 00:00:00 UTC`)
3. Wednesday, 13 March 2024 00:00 (`Wed, 13 Mar 2024 00:00:00 UTC`)

Understanding Cron Expressions

Cron expressions consist of five fields separated by spaces:

┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of the month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)
│ │ │ │ │                                   
│ │ │ │ │
│ │ │ │ │
* * * * *

Common Patterns

PatternDescriptionExample
*Any value* * * * * = run every minute
,Value list separator1,15 * * * * = run at minute 1 and 15
-Range of values1-5 * * * * = run every minute from 1 through 5
/Step values*/15 * * * * = run every 15 minutes
0-59Allowed values for minutes0 * * * * = run at minute 0 (top of every hour)
0-23Allowed values for hours0 0 * * * = run at midnight (00:00)
1-31Allowed values for days of the month0 0 1 * * = run at midnight on the 1st of every month
1-12Allowed values for months0 0 * 1 * = run at midnight every day in January
0-6Allowed values for days of the week (0=Sunday)0 0 * * 0 = run at midnight on Sundays

Platform-Specific Implementation Notes

In Discord:
- Uses named parameters (e.g., `expression:`, `count:`)
- Response appears in a formatted message with Discord timestamp formatting
- Common expressions can be chosen from a dropdown in the command interface
- Error messages appear only to the user who ran the command

Use Cases

  • Schedule recurring tasks in systems and applications
  • Configure automated backups
  • Set up periodic data processing jobs
  • Automate system maintenance tasks
  • Plan recurring notifications or reports
  • Schedule regular builds or deploys in CI/CD pipelines

Notes

  • All cron expressions use UTC time zone
  • The standard cron format with 5 fields is supported (minute, hour, day, month, weekday)
  • Special characters like @yearly, @monthly, etc. are not supported
  • The maximum number of next executions that can be displayed is 10