|
Configuring and using CRONInstalling cron:
Using croncron looks for scheduled jobs in several places:
I'll concentrate on 3 for now. The crontab command:crontab -e Runs a text editor, allowing you to edit your crontab file. crontab -l Lists the contents of your crontab file. crontab -r removes your crontab file. crontab <filename> replaces your crontab file with the contents of the named file. crontab - 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 formatEach line consists of either:
Comments:You may want to paste the following at the beginning of your crontab for reference:
Environment variablesMAILTO 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 linesA 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:
Special lines:
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 formatBy "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 |