Debian Codegraph @

upstream/debian-unstable/man5/crontab.5

raw
1 '\" t
2 .\" Title: Crontab
3 .\" Author: Paul Vixie <[email protected]>
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\" Date: 2026-04-27
6 .\" Manual: crontab User Manual
7 .\" Source: crontab
8 .\" Language: English
9 .\"
10 .TH "CRONTAB" "5" "2026\-04\-27" "crontab" "crontab User Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 crontab \- tables for driving cron
32 .SH "DESCRIPTION"
33 .PP
34 A
35 \fIcrontab\fR
36 file contains instructions to the
37 \fBcron\fR(8)
38 daemon of the general form:
39 \(lqrun this command at this time on this date\(rq\&. Each user has their own crontab, and commands in any given crontab will be executed as the user who owns the crontab\&. Uucp and News will usually have their own crontabs, eliminating the need for explicitly running
40 \fBsu\fR(1)
41 as part of a cron command\&.
42 .PP
43 Note that comments on the same line as cron commands are not interpreted as comments in the cron sense, but are considered part of the command and passed to the shell\&. This is similarly true for comments on the same line as environment variable settings\&.
44 .PP
45 An active line in a crontab will be either an environment setting or a cron command\&. An environment setting is of the form,
46 .sp
47 .if n \{\
48 .RS 4
49 .\}
50 .nf
51 name = value
52
53 .fi
54 .if n \{\
55 .RE
56 .\}
57 .sp
58 where the spaces around the equal\-sign (=) are optional, and any subsequent non\-leading spaces in
59 \fIvalue\fR
60 will be part of the value assigned to
61 \fIname\fR\&. The
62 \fIvalue\fR
63 string may be placed in quotes (single or double, but matching) to preserve leading or trailing blanks\&. To define an empty variable, quotes can be used\&.
64 .PP
65 The
66 \fIvalue\fR
67 string is not parsed for environmental substitutions or replacement of variables or tilde(~) expansion, thus lines like
68 .sp
69 .if n \{\
70 .RS 4
71 .\}
72 .nf
73 PATH=$HOME/bin:$PATH
74 PATH=~/bin:/usr/bin
75
76 .fi
77 .if n \{\
78 .RE
79 .\}
80 .sp
81 will not work as you might expect\&. And neither will this work\&.
82 .sp
83 .if n \{\
84 .RS 4
85 .\}
86 .nf
87 A=1
88 B=2
89 C=$A $B
90
91 .fi
92 .if n \{\
93 .RE
94 .\}
95 .sp
96 There will not be any substitution for the defined variables in the last value\&. However, with most shells you can also try e\&.g\&.,:
97 .sp
98 .if n \{\
99 .RS 4
100 .\}
101 .nf
102 P=PATH=/a/b/c:$PATH
103 33 22 1 2 3 eval $P && some commands
104
105 .fi
106 .if n \{\
107 .RE
108 .\}
109 .sp
110 Several environment variables are set up automatically by the
111 \fBcron\fR(8)
112 daemon\&.
113 \fISHELL\fR
114 is set to
115 \fI/usr/bin/sh\fR, and
116 \fILOGNAME\fR
117 and
118 \fIHOME\fR
119 are set from the
120 \fI/etc/passwd\fR
121 line of the crontab\*(Aqs owner\&.
122 \fIHOME\fR
123 and
124 \fISHELL\fR
125 may be overridden by settings in the crontab;
126 \fILOGNAME\fR
127 may not\&.
128 .PP
129 (Another note: the
130 \fILOGNAME\fR
131 variable is sometimes called
132 \fIUSER\fR
133 on BSD systems\&.\&.\&. on these systems,
134 \fIUSER\fR
135 will be set also\&.)
136 .PP
137 In addition to
138 \fILOGNAME\fR,
139 \fIHOME\fR, and
140 \fISHELL\fR,
141 \fBcron\fR(8)
142 will look at
143 \fIMAILTO\fR
144 if it has any reason to send mail as a result of running commands in
145 \(lqthis\(rq
146 crontab\&. If
147 \fIMAILTO\fR
148 is defined (and non\-empty), mail is sent to the user so named\&. If\fI MAILTO\fR
149 is defined but empty (MAILTO=""), no mail will be sent\&. Otherwise mail is sent to the owner of the crontab\&. This option is useful if you decide on
150 \fB/usr/bin/mail\fR
151 instead of
152 \fB/usr/lib/sendmail\fR
153 as your mailer when you install cron \-\-
154 \fB/usr/bin/mail\fR
155 doesn\*(Aqt do aliasing, and UUCP usually doesn\*(Aqt read its mail\&.
156 .PP
157 The format of a cron command is very much the V7 standard, with a number of upward\-compatible extensions\&. Each line has five time and date fields, followed by a command, followed by a newline character (\*(Aq\en\*(Aq)\&. The system crontab (\fI/etc/crontab\fR) uses the same format, except that the username for the command is specified after the time and date fields and before the command\&. The fields may be separated by spaces or tabs\&. The maximum permitted length for the command field is 998 characters\&.
158 .PP
159 Commands are executed by
160 \fBcron\fR(8)
161 when the minute, hour, and month of year fields match the current time, and when at least one of the two day fields (day of month, or day of week) match the current time (see
162 \(lqNote\(rq
163 below)\&.
164 \fBcron\fR(8)
165 examines cron entries once every minute\&. The time and date fields are:
166 .TS
167 allbox tab(:);
168 lB lB.
169 T{
170 field
171 T}:T{
172 allowed\ \&values\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&
173 T}
174 .T&
175 l l
176 l l
177 l l
178 l l
179 l l.
180 T{
181 minute
182 T}:T{
183 0\-59
184 T}
185 T{
186 hour
187 T}:T{
188 0\-23
189 T}
190 T{
191 day of month
192 T}:T{
193 1\-31
194 T}
195 T{
196 month
197 T}:T{
198 1\-12 (or names, see below)
199 T}
200 T{
201 day of week
202 T}:T{
203 0\-7 (0 or 7 is Sun, or use names)
204 T}
205 .TE
206 .sp 1
207 .PP
208 A field may be an asterisk (*), which always stands for
209 \(lqfirst\-last\(rq\&.
210 .PP
211 Ranges of numbers are allowed\&. Ranges are two numbers separated with a hyphen\&. The specified range is inclusive\&. For example, 8\-11 for an
212 \(lqhours\(rq
213 entry specifies execution at hours 8, 9, 10 and 11\&.
214 .PP
215 Lists are allowed\&. A list is a set of numbers (or ranges) separated by commas\&. Examples:
216 \(lq1,2,5,9\(rq,
217 \(lq0\-4,8\-12\(rq\&.
218 .PP
219 Step values can be used in conjunction with ranges\&. Following a range with
220 \(lq/<number>\(rq
221 specifies skips of the number\*(Aqs value through the range\&. For example,
222 \(lq0\-23/2\(rq
223 can be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is
224 \(lq0,2,4,6,8,10,12,14,16,18,20,22\(rq)\&. Steps are also permitted after an asterisk, so if you want to say
225 \(lqevery two hours\(rq, just use
226 \(lq*/2\(rq\&.
227 .PP
228 Names can also be used for the
229 \(lqmonth\(rq
230 and
231 \(lqday of week\(rq
232 fields\&. Use the first three letters of the particular day or month (case doesn\*(Aqt matter)\&. Examples for the month are:
233 \(lqJan\-Mar\(rq
234 or
235 \(lqJan,Mar\(rq
236 \&. Examples for the day of week are;
237 \(lqMon\-Wed\(rq
238 or
239 \(lqMon\-Wed\(rq\&. Names are in English language\&.
240 .PP
241 The
242 \(lqsixth\(rq
243 field (the rest of the line) specifies the command to be run\&. The entire command portion of the line, up to a newline or % character, will be executed by
244 \fB/usr/bin/sh\fR
245 or by the shell specified in the
246 \fISHELL\fR
247 variable of the cronfile\&. Percent\-signs (%) in the command, unless escaped with backslash (\e), will be changed into newline characters, and all data after the first % will be sent to the command as standard input\&.
248 .PP
249 Note: The day of a command\*(Aqs execution can be specified by two fields \(em day of month, and day of week\&. If both fields are restricted (i\&.e\&., aren\*(Aqt *), the command will be run when either field matches the current time\&. For example,
250 \(lq30 4 1,15 * 5\(rq
251 would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday\&. One can, however, achieve the desired result by adding a test to the command (see the last example in EXAMPLE CRON FILE below)\&.
252 .PP
253 Instead of the first five fields, one of eight special strings may appear:
254 .TS
255 allbox tab(:);
256 lB lB.
257 T{
258 string
259 T}:T{
260 meaning\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&\ \&
261 T}
262 .T&
263 l l
264 l l
265 l l
266 l l
267 l l
268 l l
269 l l
270 l l.
271 T{
272 @reboot
273 T}:T{
274 Run once, at startup\&.
275 T}
276 T{
277 @yearly
278 T}:T{
279 Run once a year, "0 0 1 1 *"\&.
280 T}
281 T{
282 @annually
283 T}:T{
284 (same as @yearly)
285 T}
286 T{
287 @monthly
288 T}:T{
289 Run once a month, "0 0 1 * *"\&.
290 T}
291 T{
292 @weekly
293 T}:T{
294 Run once a week, "0 0 * * 0"\&.
295 T}
296 T{
297 @daily
298 T}:T{
299 Run once a day, "0 0 * * *"\&.
300 T}
301 T{
302 @midnight
303 T}:T{
304 (same as @daily)
305 T}
306 T{
307 @hourly
308 T}:T{
309 Run once an hour, "0 * * * *"\&.
310 T}
311 .TE
312 .sp 1
313 .PP
314 Please note that startup, as far as @reboot is concerned, is the time when the
315 \fBcron\fR(8)
316 daemon startup\&. In particular, it may be before some system daemons, or other facilities, were startup\&. This is due to the boot order sequence of the machine\&.
317 .PP
318 .PP
319 .SH "EXAMPLE CRON FILE"
320 .PP
321 .if n \{\
322 .RS 4
323 .\}
324 .nf
325 # use /usr/bin/sh to run commands, no matter what /etc/passwd says
326 SHELL=/usr/bin/sh
327 # mail any output to `paul\*(Aq, no matter whose crontab this is
328 MAILTO=paul
329 #
330 # run five minutes after midnight, every day
331 5 0 * * * $HOME/bin/daily\&.job >> $HOME/tmp/out 2>&1
332 # run at 2:15pm on the first of every month \-\- output mailed to paul
333 15 14 1 * * $HOME/bin/monthly
334 # run at 10 pm on weekdays, annoy Joe
335 0 22 * * 1\-5 mail \-s "It\*(Aqs 10pm" joe%Joe,%%Where are your kids?%
336 23 0\-23/2 * * * echo "run 23 minutes after midn, 2am, 4am \&.\&.\&., everyday"
337 5 4 * * sun echo "run at 5 after 4 every Sunday"
338 0 */4 1 * mon echo "run every 4th hour on the 1st and on every Monday"
339 0 0 */2 * sun echo "run at midn on every Sunday that\*(Aqs an uneven date"
340 # Run on every second Saturday of the month
341 0 4 8\-14 * * test $(date +\e%u) \-eq 6 && echo "2nd Saturday"
342 # Same thing, efficient too:
343 0 4 * * * Sat d=$(date +e) && test $d \-ge 8 \-a $d \-le 14 && echo "2nd Saturday"
344 #Execute early the next morning following the first
345 #Thursday of each month
346 57 2 * * 5 case $(date +d) in 0[2\-8]) echo "After 1st Thursday"; esac
347
348 .fi
349 .if n \{\
350 .RE
351 .\}
352 .PP
353 All the above examples run non\-interactive programs\&. If you wish to run a program that interacts with the user\*(Aqs desktop you have to make sure the proper environment variable
354 \fIDISPLAY\fR
355 is set\&.
356 .sp
357 .if n \{\
358 .RS 4
359 .\}
360 .nf
361 # Execute a program and run a notification every day at 10:00 am
362 0 10 * * * $HOME/bin/program | DISPLAY=:0 notify\-send "Program run" "$(cat)"
363
364 .fi
365 .if n \{\
366 .RE
367 .\}
368 .sp
369 .SH "EXAMPLE SYSTEM CRON FILE"
370 .PP
371 The following lists the content of a regular system\-wide crontab file\&. Unlike a user\*(Aqs crontab, this file has the username field, as used by
372 \fI/etc/crontab\fR\&.
373 .sp
374 .if n \{\
375 .RS 4
376 .\}
377 .nf
378 # /etc/crontab: system\-wide crontab
379 # Unlike any other crontab you don\*(Aqt have to run the `crontab\*(Aq
380 # command to install the new version when you edit this file
381 # and files in /etc/cron\&.d\&. These files also have username fields,
382 # that none of the other crontabs do\&.
383
384 SHELL=/bin/sh
385 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
386
387 # Example of job definition:
388 # \&.\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- minute (0 \- 59)
389 # | \&.\-\-\-\-\-\-\-\-\-\-\-\-\- hour (0 \- 23)
390 # | | \&.\-\-\-\-\-\-\-\-\-\- day of month (1 \- 31)
391 # | | | \&.\-\-\-\-\-\-\- month (1 \- 12) OR jan,feb,mar,apr \&.\&.\&.
392 # | | | | \&.\-\-\-\- day of week (0 \- 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
393 # m h dom mon dow usercommand
394 17 * * * * root cd / && run\-parts \-\-report /etc/cron\&.hourly
395 25 6 * * * root test \-x /usr/sbin/anacron || ( cd / && run\-parts \-\-report /etc/cron\&.daily )
396 47 6 * * 7 root test \-x /usr/sbin/anacron || ( cd / && run\-parts \-\-report /etc/cron\&.weekly )
397 52 6 1 * * root test \-x /usr/sbin/anacron || ( cd / && run\-parts \-\-report /etc/cron\&.monthly )
398 #
399
400 .fi
401 .if n \{\
402 .RE
403 .\}
404 .PP
405 Note that all the system\-wide tasks will run, by default, from 6 am to 7 am\&. In the case of systems that are not powered on during that period of time, only the hourly tasks will be executed unless the defaults above are changed\&.
406 .SH "YET ANOTHER EXAMPLE"
407 .PP
408 In that example one can see that numbers can be prepended some 0, in order to line up columns\&.
409 .sp
410 .if n \{\
411 .RS 4
412 .\}
413 .nf
414 17 * * * * root cd / && run\-parts \-\-report /etc/cron\&.hourly
415 25 16 * * * root test \-x /usr/sbin/anacron || ( cd / && run\-parts \-\-report /etc/cron\&.daily )
416 47 06 * * 7 root test \-x /usr/sbin/anacron || ( cd / && run\-parts \-\-report /etc/cron\&.weekly )
417 52 06 1 * * root test \-x /usr/sbin/anacron || ( cd / && run\-parts \-\-report /etc/cron\&.monthly )
418
419 .fi
420 .if n \{\
421 .RE
422 .\}
423 .sp
424 .SH "SEE ALSO"
425 .PP
426 \fBcron\fR(8),
427 \fBcrontab\fR(1)
428 .SH "EXTENSIONS"
429 .PP
430 When specifying day of week, both day 0 and day 7 will be considered Sunday\&. BSD and AT&T seem to disagree about this\&.
431 .PP
432 Lists and ranges are allowed to co\-exist in the same field\&. "1\-3,7\-9" would be rejected by AT&T or BSD cron \-\- they want to see "1\-3" or "7,8,9" ONLY\&.
433 .PP
434 Ranges can include "steps", so "1\-9/2" is the same as "1,3,5,7,9"\&.
435 .PP
436 Names of months or days of the week can be specified by name\&.
437 .PP
438 Environment variables can be set in the crontab\&. In BSD or AT&T, the environment handed to child processes is basically the one from
439 \fI/etc/rc\fR\&.
440 .PP
441 Command output is mailed to the crontab owner (BSD can\*(Aqt do this), can be mailed to a person other than the crontab owner (SysV can\*(Aqt do this), or the feature can be turned off and no mail will be sent at all (SysV can\*(Aqt do this either)\&.
442 .PP
443 All of the
444 \(lq@\(rq
445 commands that can appear in place of the first five fields are extensions\&.
446 .SH "LIMITATIONS"
447 .PP
448 The
449 \fBcron\fR
450 daemon runs with a defined timezone\&. It currently does not support per\-user timezones\&. All the tasks: system\*(Aqs and user\*(Aqs will be run based on the configured timezone\&. Even if a user specifies the
451 \fITZ\fR
452 environment variable in his crontab this will affect only the commands executed in the crontab, not the execution of the crontab tasks themselves\&. If one wants to specify a particular timezone for crontab tasks, one may check the date in the child script, for example:
453 .sp
454 .if n \{\
455 .RS 4
456 .\}
457 .nf
458 # m h dom mon dow command
459
460 TZ=UTC
461 0 * * * * [ "$(date +\e%R)" = 00:00 ] && run_some_script
462
463 .fi
464 .if n \{\
465 .RE
466 .\}
467 .PP
468 POSIX specifies that the day of month and the day of week fields both need to match the current time if either of them
469 \fIis\fR
470 a *\&. However, this implementation only checks if the
471 \fIfirst character\fR
472 is a *\&. This is why "0 0 */2 * sun" runs every Sunday that\*(Aqs an uneven date while the POSIX standard would have it run every Sunday and on every uneven date\&.
473 .PP
474 The
475 \fBcrontab\fR
476 syntax does not make it possible to define all possible periods one can imagine\&. For example, it is not straightforward to define the last weekday of a month\&. To have a task run in a time period that cannot be defined using
477 \fIcrontab\fR
478 syntax, the best approach would be to have the program itself check the date and time information and continue execution only if the period matches the desired one\&.
479 .PP
480 If the program itself cannot do the checks then a wrapper script would be required\&. Useful tools that could be used for date analysis are
481 \fBncal\fR(1)
482 or
483 \fBcalendar\fR(1)\&. For example, to run a program the last Saturday of every month you could use the following wrapper code:
484 .sp
485 .if n \{\
486 .RS 4
487 .\}
488 .nf
489 0 4 * * Sat [ "$(date +\e%e)" = "$(LANG=C ncal | sed \-n \*(Aqs/^Sa \&.* \e([0\-9]\e+\e) *$/\e1/p\*(Aq)" ] && echo "Last Saturday" && program_to_run
490
491 .fi
492 .if n \{\
493 .RE
494 .\}
495 .PP
496 The maximum permitted length for the command field is 998 characters\&.
497 .PP
498 The recommended length should be less than 80 characters, like lines in readable source files\&. When one must use a long command, it is worth creating a dedicated script, which in turn can contain valuable comments\&.
499 .SH "USING EVAL TO WRAP MISC ENVIRONMENT SETTINGS"
500 .PP
501 The following tip is kindly provided by 積丹尼 Dan Jacobson:
502 .sp
503 .if n \{\
504 .RS 4
505 .\}
506 .nf
507 CONTENT_TYPE="text/plain; charset=UTF\-8"
508 d=eval LANG=zh_TW\&.UTF\-8 w3m \-dump
509 26 22 16 1\-12 * $d https://www\&.ptt\&.cc/bbs/transgender/index\&.html
510
511 .fi
512 .if n \{\
513 .RE
514 .\}
515 .PP
516 it won\*(Aqt work without the eval\&. Saying
517 .sp
518 .if n \{\
519 .RS 4
520 .\}
521 .nf
522 d=LANG=zh_TW\&.UTF\-8 w3m \-dump
523
524 .fi
525 .if n \{\
526 .RE
527 .\}
528 .PP
529 will get
530 .sp
531 .if n \{\
532 .RS 4
533 .\}
534 .nf
535 /bin/sh: LANG=zh_TW\&.UTF\-8: command not found
536
537 .fi
538 .if n \{\
539 .RE
540 .\}
541 .PP
542 .SH "DIAGNOSTICS"
543 .PP
544 cron requires that each entry in a crontab end in a newline character\&. If the last entry in a crontab is missing a newline (i\&.e\&. terminated by EOF), cron will consider the crontab (at least partially) broken\&. A warning will be written to syslog\&.
545 .SH "AUTHORS"
546 .PP
547 \fBPaul Vixie\fR <\&paul@vix\&.com\&>
548 .RS 4
549 Wrote this manpage (1994)\&.
550 .RE
551 .PP
552 \fBSteve Greenland\fR <\&stevegr@debian\&.org\&>
553 .RS 4
554 Maintained the package (1996\-2005)\&.
555 .RE
556 .PP
557 \fBJavier Fern\('andez\-Sanguino Pe\(~na\fR <\&jfs@debian\&.org\&>
558 .RS 4
559 Maintained the package (2005\-2014)\&.
560 .RE
561 .PP
562 \fBChristian Kastner\fR <\&ckk@debian\&.org\&>
563 .RS 4
564 Maintained the package (2010\-2016)\&.
565 .RE
566 .PP
567 \fBGeorges Khaznadar\fR <\&georgesk@debian\&.org\&>
568 .RS 4
569 Maintained the package (2022\-2024)\&.
570 .RE
571 .SH "COPYRIGHT"
572 .br
573 Copyright \(co 1994 Paul Vixie
574 .br
575 .PP
576 Distribute freely, except: don\*(Aqt remove my name from the source or documentation (don\*(Aqt take credit for my work), mark your changes (don\*(Aqt get me blamed for your possible bugs), don\*(Aqt alter or remove this notice\&. May be sold if buildable source is provided to buyer\&. No warranty of any kind, express or implied, is included with this software; use at your own risk, responsibility for damages (if any) to anyone resulting from the use of this software rests entirely with the user\&.
577 .PP
578 Since year 1994, many modifications were made in this manpage, authored by Debian Developers which maintained
579 cron(TM); above is a short list, more information can be found in the file
580 \fI/usr/share/doc/cron/copyright\fR\&.
581 .sp