A crontab file contains entries for each cron job. Entries are separated by newline characters. Each crontab file entry contains six fields separated by spaces or tabs in the following form:
Also Read: The best Job Scheduling Interview Questions
These fields accept the following values:
|minute||0 through 59|
|hour||0 through 23|
|day_of_month||1 through 31|
|month||1 through 12|
|weekday||0 through 6 for Sunday through Saturday|
|command||a shell command|
You must specify a value for each field. Except for the command field, these fields can contain the following:
- A number in the specified range. To run a command in May, specify 5 in the month field.
- Two numbers separated by a dash to indicate an inclusive range. To run a cron job on Tuesday through Friday, place 2-5 in the weekday field.
- A list of numbers separated by commas. To run a command on the first and last day of January, you would specify 1,31 in the day_of_month field.
- A combination of two numbers separated by a dash to indicate an inclusive range and a list of numbers separated by commas can be used in conjunction. To run a command on the first, tenth to sixteenth and last day of January, you would specify 1,10-16,31 in the day_of_month field. The above two points can also be used in combination.
- An * (asterisk), meaning all allowed values. To run a job every hour, specify an asterisk in the hour field.
The cron daemon runs the command named in the sixth field at the selected date and time. If you include a % (percent sign) in the sixth field, the cron daemon treats everything that precedes it as the command invocation and makes all that follows it available to standard input, unless you escape the percent sign (\%). Blank lines and lines whose first non-blank character is the number sign (#) will be ignored. If the arguments to the command have a backslash (‘\’), the backslash should be preceded by another backslash.