Skip to content

Instantly share code, notes, and snippets.

@t32k
Last active December 30, 2015 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t32k/7783444 to your computer and use it in GitHub Desktop.
Save t32k/7783444 to your computer and use it in GitHub Desktop.

Cron Pattern

Definition

A date and time format that determines when to run a scheduled job.

Structure

The cron pattern consists of six fields separated by spaces. The format is:
[second] [minute] [hour] [day of month] [month] [day of week]
The allowed values for the cron pattern fields are described in the following table:

Field Allowed Values
Second 0-59
Minute 0-59
Hour 0-23
Day of month 1-31
Month 0-11 (0 = January)
Day of week 1-7 (1 = Sunday)

To configure each field, you can use one of the following options:

  • An asterisk to run every instance of the value of the field. It is equivalent to the range [first-last]. For example, an asterisk in the Month field runs the job every month.
  • A range. The specified range is inclusive. For example, to specify a run time between the hours of 8:00 and 11:00 the range of the Hour field would be [8-11] which is equivalent to [8,9,10,11].
  • A set of numbers or ranges separated by commas. For example, if you enter [1,8-12,15] in the Day of month field, the job runs on the first, eighth, ninth, tenth, eleventh, twelfth, and fifteenth days of the month.
  • A step, used with ranges. Enter "/" after a range to specify which values to use in the range. For example, [0-23/2] can be used in the Hour field to specify that a job runs every other hour. This is equivalent to specifying [0,2,4,6,8,10,12,14,16,18,20,22] in the Hour field. Steps are also permitted after an asterisk, so if you want to run the job every two hours, you could use [*/2].

Example

Examples of cron patterns are described in the following table:

Pattern Description
            • | Runs the job every second. None of the fields are restricted. */5 * * * * * |Runs every five seconds, starting at second zero (that is, seconds 0,5,10,15,20,25,30,35,40,45,50,55) 0 * * * * * |Runs every minute, on the first second of the minute 0 0 * * * * |Runs every hour, on the first second of the minute and the first minute of the hour 0 0 */4 * * * | Runs every four hours, starting with hour zero (that is, hours 0,4,8,12,16,20) on the first second of the minute and the first minute of the hour 00 30 11 * * * |Runs every day at 11:30:00 AM 00 30 11 * * 2-6 |Runs every weekday (Monday through Friday) at 11:30:00 AM. It does not run on Saturday or Sunday. 00 30 11 1 0,6 * |Runs at 11:30:00 AM on the first of January and first of July 00 30 11 1 0 2 |Runs at 11:30:00 AM on the first of January if it is Monday. It is uncommon to specify both a [Day of Month] and a [Day of Week], but it is allowed. This job runs every few years since the first of January is not always a Monday.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment