Next: , Up: Crontab Format   [Contents][Index]

2.2.1 Cronjob Definition

A cronjob definition is a line in crontab that defines a running schedule, a user on whose behalf the job will be run (in system crontabs), and a command to be run.

The fields are delimited by arbitrary amount of whitespace.

Cronjob definition begins with a cron expression, which defines schedule for running the command. It consists of five fields in this order:

fieldallowed values
day of month1-31
month1-12, or abbreviated month names
day of week0-7 (0 or 7 is Sunday), or abbreviated day names

A field may contain a single asterisk ‘*’, which stands for “each time unit”. For example, it means “each minute” when used in the first field, “each hour” in second one, and so on. Asterisk can be followed by a slash and a decimal number, which defines a step within the interval. E.g. ‘*/2’ in second field stands for “each second hour”.

The field may also be a comma-delimited list of the following constructs:


A single number. E.g. ‘2’ in first field means “second minute of an hour”.


Two numbers delimited by a dash define a range. E.g ‘2-5’ in first field is “minutes 2,3,4, and 5 (inclusive)”. The order is important. For example, the following schedule:

55-5 * * * *

means “minutes 55 through 59 and 0 through 5 of the next hour”.


Same as above, but with step of N units, e.g.:

10-25/5 * * * *

which stands for “minutes 10,15,20,25”.

Names can be used in “month” and “day of week” fields. Day and week names are abbreviated to their first three characters (case-insensitive). Ranges or lists of names are allowed as well.

The day of command’s execution is determined by two fields: day of month, and day of week. If both are supplied (i.e. are not ‘*’), the result depends on the selected day field semantics. There are three cases:

Strict semantics

The command will be run only when both fields match the current time. For example,

30 4 1,15 * 5

means “run the command at 4:30 am each Friday between the 1st and 15th of each month”.

This semantics is the default for micrond.

Vixie semantics

The command will be run when either field matches the current time. Thus, the previous example would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.

Dillon semantics

If both day of the month and day of week are supplied, the former must be an integer number in range 1-5. Its meaning is Nth such weekday in the month. For example, to run the date command at 11 am on the second and third Monday, Tuesday and Wednesday of each month:

0 11 2,3 * mon-wed date

To request the last Monday, etc. in a month, use ‘5’. This will always match the last Monday, etc., even if there are only four Mondays in the month:

0 11 1,5 * mon-wed date

When the fourth Monday in a month is the last, it will match against both 4 and 5, but will only run once if both are specified.

The semantics to use is selected by setting the _MICRON_DAY_SEMANTICS (see _MICRON_DAY_SEMANTICS) variable to one of the following values: strict, vixie, dillon (case-insensitive).

Instead of the first five fields, the following macro-definitions can be used:


Run once, at micrond startup.


Run once a year, i.e. ‘0 0 1 1 *’.


Run once a month, ‘0 0 1 * *’.


Run once a week, ‘0 0 * * 0’.


Run once a day, ‘0 0 * * *’.


Run once an hour, ‘0 * * * *’.

In master crontab (/etc/crontab) and system crontabs (located in /etc/cron.d), the cron expression is followed by user name field, which holds a login name of the user on whose behalf the command will be run.

This field is absent in user personal crontabs, since these are always run on behalf of the user that owns them,

The remainder of line is taken as a shell command to be run when the time matches the schedule. The percent sign in the command line is special: the first occurrence of unescaped and unquoted ‘%’ delimits the command line proper and the text that will be piped to its standard input. Any unescaped occurrences of ‘%’ to the right of it will be replaced with newlines. To use a literal percent sign in the job command line, either precede it with a backslash or quote it using single or double quotes.

For example, the following command line:

mail hostmaster%Hello,%%This is a daily notification.%--%Regards from cron.%

will cause mirond to start the mail command and to supply the following text to its standard input:


This is a daily notification.
Regards from cron.

Before running the command, micrond changes the directory to the home directory of the user on whose behalf the command is run (as defined by the HOME environment variable, see HOME), modifies the environment as requested by variable settings (see Variable Settings) and runs the command as

$SHELL -c "command"

Default SHELL is ‘/bin/sh’ (see SHELL).

Next: , Up: Crontab Format   [Contents][Index]