|
|
CRON and SSMTPI'm lumping these two programs together: cron is a scheduler. It accepts instructions from one or more job files. Each instruction consists of a date and time and a command to be run at that date and time. If the command returns text then this can be sent as a report via email provided the system has a mail service installed. ssmtp is a cut-down mail sender. It simply forwards all messages to another server capable of delivering them. Typically that would be your ISP's mail server. Installing cron:
Installing ssmtp:
In both cases the package installed itself fully. The cron package included the startup script and a start command so it will be running now. ssmtp needs a bit of configuration If you really can't figure out what's going on it's possible to install an evaluation copy of a mailserver on windows and then set the windows PC as the mail hub. By setting the domain to "*" the server can be set to accept anything and that way you can diagnose a bad configuration. 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 |