crontab
Schedule periodic background work (POSIX)
Syntax:
crontab [-d cron_dir] [-u user] [file]
crontab [-d cron_dir] [-e | -l | -r] [-u user]
Runs on:
QNX OS
Options:
- -d cron_dir
- The location of the crontab directory.
- -e
- Edit a user's crontab entry. If you don't specify the -u option, crontab edits your own entry. It uses vi unless the EDITOR environment variable names another editor.
- -l
- (
el
) List the crontab entry of the user. Without the -u option, the invoking user's entry is listed. - -r
- Remove a user's crontab entry. Without the -u option, the invoking user's entry is removed.
- -u user
- Specify the user whose crontab is to be acted upon. When submitting a crontab, the new crontab entry replaces or creates that user's crontab. When removing (-r) or listing (-l) existing crontabs, this specifies which user's crontab to remove or list. Only root may use this option.
- file
- The pathname of a file that contains specifications for crontab entries (see the Description section for the format for these specifications). If no file is specified, crontab uses standard input.
Description:
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, standard input is used.
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.
- minute (0-59)
- hour (0-23)
- day of the month (1-31)
- month of the year (1-12)
- day of the week (0-6 with 0=Sunday)
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.
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.
*
. 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's 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.
Sample crontab entries
1 0 * * * calendar -
1,21,41 * * * * (echo -n " "; date; echo) > /dev/con1
30 5 * * 1-5 /usr/lib/uucp/uuclean
0 4 * * * find /tmp -mtime +7 -exec rm -f {} \;
Examples:
crontab -l
Files:
When an error occurs, a diagnostic message is written to standard error.
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.
- cron.allow
- If this file exists, it's read by crontab to determine the exclusive list of userids who are allowed to schedule cron jobs.
- cron.deny
- If cron.allow doesn't exist, crontab reads this file to determine a list of userids who are NOT allowed to schedule cron jobs.
- crontabs/userid
- The crontab utility may create, edit, list or remove this file.
Exit status:
- 0
- Successful completion.
- >0
- An error occurred.
Caveats:
If you inadvertently enter the crontab utility with no argument, don't try to get out by typing CtrlD (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 CtrlC.