Schedule periodic background work (POSIX)
crontab [-d cron_dir] [-u user] [file] crontab [-d cron_dir] [-e | -l | -r] [-u user]
Neutrino
The crontab utility creates or replaces a user's crontab entry. You can input the new crontab entry by specifying a file that contains specifications for crontab entries. If you don't specify a file, the standard input is used.
This utility needs to have the setuid (“set user ID”) bit set in its permissions. If you use mkefs, mketfs, or mkifs on a Windows host to include this utility in an image, use the perms attribute to specify its permissions explicitly, and the uid and gid attributes to set the ownership correctly. |
Users may use crontab if their names appear in the /var/spool/cron/cron.allow file. If that file doesn't exist, the file /var/spool/cron/cron.deny is checked to determine whether the user should be denied access to crontab. If neither file exists, only the superuser is allowed to modify crontab entries. If cron.allow doesn't exist and cron.deny exists and is empty, then global usage is allowed. These permission files consist of one user name per line.
Each command you specify is executed from your home directory using the shell (/bin/sh). The cron utility supplies a default environment for the shell, defining HOME, LOGNAME, SHELL(=/bin/sh), PATH (=:/bin:/usr/bin) and TZ. Users who want to have their .profile executed must explicitly do so in their crontab entry.
A crontab entry consists of lines of six fields each. The fields are separated by blanks. The first five are integer patterns that specify the following:
Each of these patterns can be an asterisk (meaning all valid values), an element, a list of elements separated by commas, or a range separated by a hyphen (-).
An element is either a number or two numbers separated by a hyphen (meaning an inclusive range). You can specify days by two fields (day of the month and day of the week). If both are specified, both are adhered to.
As an example of specifying the two types of days, the following line:
0 0 1,15 * 1
runs a command at 00:00h on the first and fifteenth of each month, as well as at 00:00h on every Monday. To specify days with only one field, the other field should be set to *. For example:
0 0 * * 1
runs a command only on Mondays.
The sixth field of a line in a crontab entry is a string that is executed by the command interpreter at the specified times. A percent character in this field — unless escaped by a backslash — is translated to a newline character.
Only the first line (up to a % or end-of-line) of the command field is executed by the command interpreter.
Invoke the calendar program each day one minute after midnight:
1 0 * * * calendar -
Display the current time on the system console every 20 minutes:
1,21,41 * * * * (echo -n " "; date; echo) > /dev/con1
Clean up the UUCP work directories each weekday at 5:30 am:
30 5 * * 1-5 /usr/lib/uucp/uuclean
Remove any files under /tmp that haven't been modified in more than seven days:
0 4 * * * find /tmp -mtime +7 -exec rm -f {} \;
If you want the output from your commands, redirect it to a file. |
List your own crontab entry:
crontab -l
When an error occurs, a diagnostic message is written to the standard error.
The standard input may be read for the content of crontab files when they are being created (none of -e, -l or -r are specified) and no file is specified on the command line.
When a crontab file is being edited, the editor invoked by crontab inherits crontab's standard input, standard output, and standard error.
The following files relative to one of /var/spool/cron, or the directory named in the -d option are used by crontab:
If you inadvertently enter the crontab utility with no argument, don't try to get out by typing Ctrl-D (end-of-file), since this would replace your crontab file with an empty file. In this case, you should exit by typing your interrupt character, which is typically Ctrl-C.