crontab — stdin stdout - file -- opt --help --version
crontab [options
] [file
]
The crontab
command, like
at
, schedules jobs for specific
times. However, crontab
is for
recurring jobs, such as “Run this command at midnight on the second
Tuesday of each month.” To make this work, you edit and save a file
(called your crontab file), which
automatically gets installed in a system directory (/var/spool/cron). Once a minute, a Linux
process called cron
wakes up,
checks your crontab file, and executes any jobs that are
due.
$ crontab -e
Edit your crontab file in your default editor ($EDITOR
)
$ crontab -l
Print your crontab file on standard output
$ crontab -r
Delete your crontab file
$ crontab myfile
Install the file myfile as your crontab file
The superuser can add the option -u
username
to
work with other users’ crontab files.
Crontab files contain one job per line. (Blank lines and
comment lines beginning with “#
” are ignored.)
Each line has six fields, separated by whitespace. The first five
fields specify the time to run the job, and the last is the job
command itself.
Integers between 0 and 59. This can be a single number
(30
), a sequence of numbers
separated by commas (0,15,30,45
), a range (20–30
), a sequence of ranges
(0-15,50-59
), or an
asterisk to mean “all.” You can also specify “every
n
th time” with the suffix /
n
; for
instance, both */12
and
0-59/12
mean 0,12,24,36,48
(i.e., every 12
minutes).
Same syntax as for minutes.
Integers between 1 and 31; again, you may use sequences, ranges, sequences of ranges, or an asterisk.
Integers between 1 and 12; again, you may use sequences,
ranges, sequences of ranges, or an asterisk. Additionally, you
may use three-letter abbreviations (jan
, feb
, mar
, ...), but not in ranges or
sequences.
Integers between 0 (Sunday) and 6 (Saturday); again, you
may use sequences, ranges, sequences of ranges, or an
asterisk. Additionally, you may use three-letter abbreviations
(sun
, mon
, tue
, ...), but not in ranges or
sequences.
Any shell command, which will be executed in your login
environment, so you can refer to environment variables like
$HOME
and expect them to
work. Use only absolute paths to your commands (e.g.,
/usr/bin/who instead of
who
) as a general
rule.
Some example time specifications are:
* * * * *
|
Every minute |
45 * * * *
|
45 minutes after each hour (1:45, 2:45, etc.) |
45 9 * * *
|
Every day at 9:45 am |
45 9 8 * *
|
The eighth day of every month at 9:45 am |
45 9 8 12 *
|
Every December 8 at 9:45 am |
45 9 8 dec *
|
Every December 8 at 9:45 am |
45 9 * * 6
|
Every Saturday at 9:45 am |
45 9 * * sat
|
Every Saturday at 9:45 am |
45 9 * 12 6
|
Every Saturday in December, at 9:45 am |
45 9 8 12 6
|
Every Saturday in December, plus December 8, at 9:45 am |
If the command produces any output upon execution, cron
will email it to you.
3.139.107.241