Using cron
The Unix cron
command is one of those things
that makes you wonder how you ever got along without it. In brief, it
lets you schedule a command or series of commands to be run
periodically on the Unix server, whether you’re logged in or
not.
The instructions on what commands to run and when to run them are
stored in a special cron table
, or
crontab
. On many systems only the superuser can
use the crontab
command to modify the entries in
that table. On other systems ordinary users can do so, but the exact
method sometimes varies depending on what flavor of Unix the server
is running.
Tip
The following discussion assumes you are on a Linux server that has
been configured to allow ordinary users to install their own
crontab
entries. If these instructions don’t
work in your case, you should contact your system administrator. You
should also try consulting the cron
and
crontab
documentation available on your server
(via man
cron
,
man
1
crontab
, and man
5
crontab
) because some of the
features described here could well be different or absent in the case
of your particular cron
installation.
A crontab
file is simply a text file. You edit
it using any text editor you like, then install it on your server
using the crontab
command, like this:
[jbc@andros jbc] crontab
mycronfile.txt
The format of the crontab
file is very specific.
Blank lines are ignored, as are lines beginning with a hash sign
(#
). All other lines need to consist of the
following fields, separated by spaces:
Minute ...
Get Perl for Web Site Management now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.