Mail collection - crontab entry




Cron is a daemon program that is started up when you boot Linux and continually runs in the background. Its only job is to read a collection of crontab files and run the command specified there at the required times.

The crontab files are kept in /var/spool/cron/crontabs. There is one file for each user who has asked for commands to be run by cron. However you should not edit the files directly, but only as described below.

Since the mail collection must be run by root, you should become superuser before you try to set up your crontab entry.

This is how to do it:

# crontab -e
(This invokes vi; you can then type in the required entry at the bottom of the existing crontab file. When you write the file away, the crontab entry will be updated.)

This is the entry you need to put in (with appropriate amendments for your own requirements):

# Collect mail from ISP
01 07-17,20,22 * * * /usr/local/etc/poll.mail
The first five space-separated fields in the line specify the time at which the command is to be run. The rest of the line is the command itself.

The time fields are, in order:

  1. minute of the hour, from 0 to 59
  2. hour of the day, from 0 to 23
  3. day of the month, from 1 to 31
  4. month of the year, from 1 to 12, and
  5. day of the week, from 0 to 6 (Sunday = 0 and Saturday = 6).
If there is an asterisk in a field, it means that every possible value is used. So my crontab entry says to run poll.mail at 1 minute past every hour from 7 am to 5 pm and at 1 minute past 8 pm and 10 pm. This is to happen every day of the year.

Up to the Automatic mail collection and delivery page

Last updated on 27th October 1996 by Oliver Elphick