Next Previous Contents

3. Setting When the Command Should Run

You need to specify exactly when you want the recurring command to run. The cron daemon wakes up every minute and checks to see if a process is scheduled. The process will only run when all of the fields are true (except for the days of the month and days of the week fields).

The days of the month and days of the week fields both specify days for a process to be run. If neither of the two fields are *, then processes will run if either of the two fields or both are true. If one of the two fields is *, then the process will run whenever the other field is true. If both fields are *, then the process runs every day.

If you need to adjust system time forward (for example, during daylight savings time), any jobs that were scheduled to run during the skipped time will not be run. If time is adjusted backwards (again, daylight savings time is the example), then a job may be processed twice.

If you're adding a recurring process to an already heavily loaded server, you should be aware of when other processes are scheduled. Big jobs are best scheduled for when the system is not heavily loaded. For most systems, this would normally be at night, but it depends upon your system and your setup.

An asterisk (*) indicates that the process should run every time period (for example, a * in the "Months" field indicates that the process should run every month).

A hyphen (-) indicates that the job should be processed during a certain range of time, including the endpoints. For example, 2-5 in the month field indicates that the job will be processed in February, March, April and May.

Commas (,) should be used to separate specific entries for a time period. For example, a 5,6,11 in the month field indicates that the job will be processed in May, June and November. Commas can also separate ranges of numbers (for example, 1-3,6-9 in the month field would mean January through March and June through September).

A range of values, or an *, followed by a forward slash (/) and a number is used to step through the range of values. So a 2-10/2 in the months field indicates every other month from February through October (in other words: February, April, June, August and October). A */5 in the day field would run on every fifth day of the appropriate month(s): the 1st, the 6th, the 11th, and so on.

Months

January is 1, February is 2...December is 12. Alternatively, you can use the first three letters of the month: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov and dec. Examples:

1-6 is every month from January through June, including January and June.

1,6,12 means January, June and December.

1-12/3 or */3 both mean every third month starting with January (in other words, January, April, July, October).

1-12 or * mean every month.

Days of the month

The days of the month are from 1 to 31 (remember that some months may not have a 29th, 30th or 31st. So, if you schedule a job to run on the 31st of every month, it will not be run during certain months). Examples:

1,15,28 means the 1st, 15th and 28th of the month.

2-10 means the 2nd day through the 10th day of a month, including the 2nd and 10th.

1-31 or * means every day of the month. If the days of the week field is also *, the process will run every day. If 1-31 or * is in the days of the month field, and a restricted value (something besides *) is in the days of the week field, the job will run when the days of the week field is true.

Days of the week

Sunday is 0, Monday is 1, Tuesday is 2...Saturday is 6. Alternatively, you can use the first three letters of the day: sun, mon, tue, wed, thu, fri, sat. Examples:

2,4,6 means Tuesday, Thursday, and Saturday.

0-6 or * means every day of the week. If the days of the month field is also *, the job will run every day. 0-6 or * plus a restricted value (something besides *) in the days of the month field means that the job will only run when the days of the month field is true.

Hours

The hours of the day run from 0 (midnight) to 23 (11 p.m.). Examples:

0,1,2 means the 0000 (midnight), 0100 (1 a.m.) and 0200 (2 a.m.) hours.

0-23/2 and */2 mean 0000, 0200, 0400...2200.

Minutes

The minutes in an hour run from 0 to 59. Examples:

0,30 means on the hour and at the half hour.

0-59/5 and */5 mean every five minutes during the hour, beginning at the hour (so on the hour, at five minutes past, at ten minutes past...).


Next Previous Contents