crontab - reporting or editing your crontab file

crontab is a command which allows you to execute commands at regular time
intervals, with the added bonus that you don't have to be logged in and
that the output report is mailed to you. You can specify the intervals in
minutes, hours, days, and even months. Depending on the options, crontab
will act differently:

  -l        - Print your current crontab file.
  -e        - Edit your crontab file.
  -r        - Remove your current crontab file.
  -u  - Apply one of the above options for user . Only root
              can do that.

Let's start by editing a crontab. If you type crontab -e you will be in
front of your favorite text editor if you have set the 'EDITOR' or 'VISUAL'
environment variable, otherwise VI will be used. A line in a crontab file
is made of six fields. The first five fields are time intervals for minutes,
hours, days in the month, months and days in the week. The sixth field is
the command to be executed. Lines beginning with a # are considered to be
comments and will be ignored by crond (the program which is responsible for
executing crontab files). Here is an example of crontab:

Note: in order to print this out in a readable font, we had to break
up long lines. Therefore, some chunks must be typed on a single line.
When the '\' character ends a line, this means this line
has to be continued. This convention works in Makefile files and
in the shell, as well as in other contexts.

# If you don't want to be sent mail, just comment
#   out the following line
#MAILTO=""
#
# Report every 2 days about new images at 2 pm,
#   from the example above - after that, "retouch"
#   the "stamp" file. The "%" is treated as a
#   newline, this allows you to put several
#   commands in a same line.
0 14 */2 * *  find /shared/images              \
  -cnewer /shared/images/stamp                 \
  -a -iregex ".*\.jpe?g"                       \
  -a -not -regex                               \
    ".*/old/.*"%touch /shared/images/stamp
#
# Every Christmas, play a melody :)
0 0 25 12 * mpg123 $HOME/sounds/merryxmas.mp3
#
# Every Tuesday at 5pm, print the shopping list...
0 17 * * 2 lpr $HOME/shopping-list.txt

There are several other ways to specify intervals than the ones shown in
this example. For example, you can specify a set of discrete values separated
by commas (1,14,23) or a range (1-15), or even combine both of them
(1-10,12-20), optionally with a step (1-12,20-27/2).