cron looks for scheduled jobs in several places:
I'll concentrate on 3 for now.
The crontab command:
Runs a text editor, allowing you to edit your crontab file.
Lists the contents of your crontab file.
removes your crontab file.
replaces your crontab file with the contents of the named file.
replaces your crontab file with input from stdin (best used with "pipes").
other options: -u <username>
edits the crontab file belonging to another user. This option probably requires you to be "root".
The basic crontab file format
Each line consists of either:
You may want to paste the following at the beginning of your crontab for reference:
MAILTO sets the destination for cron reports
I strongly recommend that you set the MAILTO variable as it ensures that the report will go where you expect. The default destination may well be wrong.
Time and date lines
A normal entry consists of five numbers giving the minute, hour, day, month, day of week followed by the command to be executed.
The numbers are separated by spaces NOT commas. An asterisk "*" denotes a wildcard so to run "command" every day at 6am you might write:
As a general rule you should use the day of week OR day of month options but not both, if both are specified then cron will execute the command if either match.
You can match multiple values using commas, so to run the above job on Mondays, Wednesdays and Fridays write:
You can match ranges using a dash so to run every weekday:
You can modify a wildcard to match special intervals using a slash, so to run every three hours:
You can combine conditions, so to run every three hours but only on weekdays:
The @reboot line is particularly interesting as it's a handy way to start a service without installing a start-stop script or run a service as a user other than root.
The master crontab format
By "Master" I am referring to the crontabs located in /etc
These are not edited by the crontab command so they are a good place to put crontab lines that start administrative tools that you do not want tampered with.
The format is similar to the above except an extra column is added between the date and the command giving the username that the command should run as eg:
These commands can be put in a text file called /etc/crontab,
Please note: I could not get the @reboot special line to function when put in /etc/crontab