CRONTAB(C) UNIX System V
Name
crontab - schedule commands to be executed at regular
intervals
Syntax
crontab [ file ]
crontab -r
crontab -l
Description
The crontab command can be used to schedule commands to be
executed at regular intervals. These commands are stored in
the user's crontab file, /usr/spool/cron/crontabs/username.
Any output or errors generated by the commands are mailed to
the user.
If called with no options, crontab copies the specified
file, or standard input if no file is specified, into the
crontabs directory (if the user has a previous crontab file,
it is replaced).
The -r option removes the user's crontab file from the
crontab directory.
The -l option lists the contents of the user's crontab file.
If the file /usr/lib/cron/cron.allow exists, only the users
listed in that file are allowed to use crontab. If
cron.allow does not exist, and the file
/usr/lib/cron/cron.deny does, then all users not listed in
cron.deny are allowed access to crontab, with an empty
cron.deny allowing global usage. If neither file exists,
only the super user is allowed to submit a job. The
allow/deny files consist of one user name per line.
The crontabs files consist of lines of six fields each. The
fields are separated by spaces or tabs. The first five are
integer patterns that specify the minute (0-59), hour (0-
23), day of the month (1-31), month of the year (1-12), and
day of the week (0-6, with 0=Sunday). Each of these
patterns may contain:
- A number in the (respective) range indicated above
- Two numbers separated by a minus (indicating an
inclusive range)
- A list of numbers separated by commas (meaning all of
these numbers)
- An asterisk (meaning all legal values)
Note that the specification of days may be made by two
fields (day of the month and day of the week). If both are
specified as a list of elements, both are adhered to. For
example, 0 0 1,15 * 1 would run a command on the first and
fifteenth of each month, as well as on every Monday. To
specify days by only one field, the other field should be
set to * (for example, 0 0 * * 1 would run a command only on
Mondays).
The sixth field is a string that is executed by the shell at
the specified time(s). A % in this field is translated into
a newline character. Only the first line (up to a % or
end-of-line) of the command field is executed by the shell.
The other lines are made available to the command as
standard input.
The shell is invoked from your $HOME directory with an arg0
of sh. Users who desire to have their .profile executed
must explicitly do so in the crontab file. cron supplies a
default environment for every shell, defining HOME, LOGNAME,
SHELL(=/bin/sh), and PATH(=/bin:/usr/bin:).
Examples
An example crontabs file follows:
0 4 * * * calendar -
15 4 * * * find /usr/preserve -mtime +7 -exec rm -f {} ;
30 4 1 * 1 /usr/lib/uucp/uuclean
40 4 * * * find / -name '#*' -atime +3 -exec rm -f {} ;
1,21,41 * * * * (echo -n ' '; date; echo ) >/dev/console
The lines in this example do the following: run the calendar
program every night at 4:00 am, clear old files from the
/etc/preserve directory every night at 4:15 am, clean up the
uucp spool directory every Monday and the first of every
month at 4:30 am, find and remove any old files with names
beginning with ``#'' every night at 4:40 am, and echo the
current date and time to the console three times an hour at
one minute, 21 minutes, and 41 minutes past the hour.
Files
/usr/lib/cron main cron directory
/usr/spool/cron/crontabs crontab directory
/usr/lib/cron/cron.allow list of allowed users
/usr/lib/cron/cron.deny list of denied users
/usr/lib/cron/.proto cron environment information
/usr/lib/cron/queuedefs
cron data file
See Also
at(C), cron(C), sh(C)
Diagnostics
crontab exits and returns a value of 55 if it cannot
allocate enough memory. If it exits for any other reason,
it returns a value of 1.
Notes
crontab commands are executed by cron(C). cron reads the
files in the crontabs directory only on startup or when a
new crontab is submitted with the crontab command, so
changes made to these files by hand will not take effect
until the system is rebooted. Changes submitted with the
crontab command will take effect as soon as cron is free to
read them (that is, when cron is not in the process of
running a scheduled job or reading another newly submitted
at(C) or crontab job.).
Users who do not wish to have output from their commands
mailed to them may want to redirect it to a file:
0 * * * * who >> /tmp/whofile 2> /dev/null
The example above would append the output of the who(C)
command to a file, and throw away any errors generated. For
more details on output redirection, see the sh(C) manual
page.
Users should remember to redirect the standard output and
standard error of their commands otherwise any generated
output or errors will be mailed to the user.
crontab will overwrite any previous crontab submitted by the
same user.
Standards Conformance
crontab is conformant with:
AT&T SVID Issue 2, Select Code 307-127;
and The X/Open Portability Guide II of January 1987.
(printed 2/15/90) CRONTAB(C)