|
|
crontab [ -e | -l | -r ]
crontab -u user [ -e | -l | -r ]
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, this is replaced.
crontab understands the following options:
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:
The sixth field is a string that is executed by the shell at the specified time (using time(S-osr5) format). 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. cron supplies a default environment for every shell, defining HOME, LOGNAME, SHELL (=/bin/sh), and PATH(=/bin:/usr/bin:).
To specify a different environment, the command specified in the crontab entry should be an executable shell script which sets the environment explicitly.
If the specified user does not exist, crontab
returns a value of 1 and an error message.
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/consoleThe 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.
Remember to redirect the standard output and standard error of commands, otherwise any generated output or errors will be mailed to you. In this example, the standard output of the who(C) is appended to the file /tmp/whofile. Output on the standard error is discarded by redirecting it to /dev/null.
0 * * * * who >> /tmp/whofile 2> /dev/nullFor more details on output redirection, see the sh(C) manual page.
crontab will overwrite any previous crontab submitted by
the same user.
Care should be taken when scheduling commands to run during time zone changes from the standard time to the daylight savings time. This is because when the clocks go forward, certain times cease to exist. For example, when the clocks go forward an hour at 2 am, all times between 2 am and 3 am (including 2 am) cease to exist. If commands are scheduled to run in this time period, then cron will still execute them at their scheduled time in the standard time zone, which will be later than expected in the local time zone. cron will warn the user of this by mail and give the exact local time that the command will be executed. It is then the user's responsibility to reschedule the job if required.
ISO/IEC DIS 99452:1992, Information technology Portable Operating System Interface (POSIX) Part 2: Shell and Utilities (IEEE Std 1003.21992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.