Debian Codegraph @

upstream/debian-trixie/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: 06/13/2025
6 .\" Manual: crontab User Manual
7 .\" Source: crontab
8 .\" Language: English
9 .\"
10 .TH "CRONTAB" "5" "06/13/2025" "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 0\-31
194 T}
195 T{
196 month
197 T}:T{
198 0\-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)\&. Ranges or lists of names are not allowed\&.
233 .PP
234 The
235 \(lqsixth\(rq
236 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
237 \fB/usr/bin/sh\fR
238 or by the shell specified in the
239 \fISHELL\fR
240 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\&.
241 .PP
242 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,
243 \(lq30 4 1,15 * 5\(rq
244 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)\&.
245 .PP
246 Instead of the first five fields, one of eight special strings may appear:
247 .TS
248 allbox tab(:);
249 lB lB.
250 T{
251 string
252 T}:T{
253 meaning
254 T}
255 .T&
256 l l
257 l l
258 l l
259 l l
260 l l
261 l l
262 l l
263 l l.
264 T{
265 @reboot
266 T}:T{
267 Run once, at startup\&.
268 T}
269 T{
270 @yearly
271 T}:T{
272 Run once a year, "0 0 1 1 *"\&.
273 T}
274 T{
275 @annually
276 T}:T{
277 (same as @yearly)
278 T}
279 T{
280 @monthly
281 T}:T{
282 Run once a month, "0 0 1 * *"\&.
283 T}
284 T{
285 @weekly
286 T}:T{
287 Run once a week, "0 0 * * 0"\&.
288 T}
289 T{
290 @daily
291 T}:T{
292 Run once a day, "0 0 * * *"\&.
293 T}
294 T{
295 @midnight
296 T}:T{
297 (same as @daily)
298 T}
299 T{
300 @hourly
301 T}:T{
302 Run once an hour, "0 * * * *"\&.
303 T}
304 .TE
305 .sp 1
306 .PP
307 Please note that startup, as far as @reboot is concerned, is the time when the
308 \fBcron\fR(8)
309 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\&.
310 .PP
311 .PP
312 .SH "EXAMPLE CRON FILE"
313 .PP
314 .if n \{\
315 .RS 4
316 .\}
317 .nf
318 # use /usr/bin/sh to run commands, no matter what /etc/passwd says
319 SHELL=/usr/bin/sh
320 # mail any output to `paul\*(Aq, no matter whose crontab this is
321 MAILTO=paul
322 #
323 # run five minutes after midnight, every day
324 5 0 * * * $HOME/bin/daily\&.job >> $HOME/tmp/out 2>&1
325 # run at 2:15pm on the first of every month \-\- output mailed to paul
326 15 14 1 * * $HOME/bin/monthly
327 # run at 10 pm on weekdays, annoy Joe
328 0 22 * * 1\-5 mail \-s "It\*(Aqs 10pm" joe%Joe,%%Where are your kids?%
329 23 0\-23/2 * * * echo "run 23 minutes after midn, 2am, 4am \&.\&.\&., everyday"
330 5 4 * * sun echo "run at 5 after 4 every Sunday"
331 0 */4 1 * mon echo "run every 4th hour on the 1st and on every Monday"
332 0 0 */2 * sun echo "run at midn on every Sunday that\*(Aqs an uneven date"
333 # Run on every second Saturday of the month
334 0 4 8\-14 * * test $(date +\e%u) \-eq 6 && echo "2nd Saturday"
335 # Same thing, efficient too:
336 0 4 * * * Sat d=$(date +e) && test $d \-ge 8 \-a $d \-le 14 && echo "2nd Saturday"
337 #Execute early the next morning following the first
338 #Thursday of each month
339 57 2 * * 5 case $(date +d) in 0[2\-8]) echo "After 1st Thursday"; esac
340
341 .fi
342 .if n \{\
343 .RE
344 .\}
345 .PP
346 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
347 \fIDISPLAY\fR
348 is set\&.
349 .sp
350 .if n \{\
351 .RS 4
352 .\}
353 .nf
354 # Execute a program and run a notification every day at 10:00 am
355 0 10 * * * $HOME/bin/program | DISPLAY=:0 notify\-send "Program run" "$(cat)"
356
357 .fi
358 .if n \{\
359 .RE
360 .\}
361 .sp
362 .SH "EXAMPLE SYSTEM CRON FILE"
363 .PP
364 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
365 \fI/etc/crontab\fR\&.
366 .sp
367 .if n \{\
368 .RS 4
369 .\}
370 .nf
371 # /etc/crontab: system\-wide crontab
372 # Unlike any other crontab you don\*(Aqt have to run the `crontab\*(Aq
373 # command to install the new version when you edit this file
374 # and files in /etc/cron\&.d\&. These files also have username fields,
375 # that none of the other crontabs do\&.
376
377 SHELL=/bin/sh
378 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
379
380 # Example of job definition:
381 # \&.\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- minute (0 \- 59)
382 # | \&.\-\-\-\-\-\-\-\-\-\-\-\-\- hour (0 \- 23)
383 # | | \&.\-\-\-\-\-\-\-\-\-\- day of month (1 \- 31)
384 # | | | \&.\-\-\-\-\-\-\- month (1 \- 12) OR jan,feb,mar,apr \&.\&.\&.
385 # | | | | \&.\-\-\-\- day of week (0 \- 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
386 # m h dom mon dow usercommand
387 17 * * * * root cd / && run\-parts \-\-report /etc/cron\&.hourly
388 25 6 * * * root test \-x /usr/sbin/anacron || ( cd / && run\-parts \-\-report /etc/cron\&.daily )
389 47 6 * * 7 root test \-x /usr/sbin/anacron || ( cd / && run\-parts \-\-report /etc/cron\&.weekly )
390 52 6 1 * * root test \-x /usr/sbin/anacron || ( cd / && run\-parts \-\-report /etc/cron\&.monthly )
391 #
392
393 .fi
394 .if n \{\
395 .RE
396 .\}
397 .PP
398 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\&.
399 .SH "YET ANOTHER EXAMPLE"
400 .PP
401 In that example one can see that numbers can be prepended some 0, in order to line up columns\&.
402 .sp
403 .if n \{\
404 .RS 4
405 .\}
406 .nf
407 17 * * * * root cd / && run\-parts \-\-report /etc/cron\&.hourly
408 25 16 * * * root test \-x /usr/sbin/anacron || ( cd / && run\-parts \-\-report /etc/cron\&.daily )
409 47 06 * * 7 root test \-x /usr/sbin/anacron || ( cd / && run\-parts \-\-report /etc/cron\&.weekly )
410 52 06 1 * * root test \-x /usr/sbin/anacron || ( cd / && run\-parts \-\-report /etc/cron\&.monthly )
411
412 .fi
413 .if n \{\
414 .RE
415 .\}
416 .sp
417 .SH "SEE ALSO"
418 .PP
419 \fBcron\fR(8),
420 \fBcrontab\fR(1)
421 .SH "EXTENSIONS"
422 .PP
423 When specifying day of week, both day 0 and day 7 will be considered Sunday\&. BSD and AT&T seem to disagree about this\&.
424 .PP
425 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\&.
426 .PP
427 Ranges can include "steps", so "1\-9/2" is the same as "1,3,5,7,9"\&.
428 .PP
429 Names of months or days of the week can be specified by name\&.
430 .PP
431 Environment variables can be set in the crontab\&. In BSD or AT&T, the environment handed to child processes is basically the one from
432 \fI/etc/rc\fR\&.
433 .PP
434 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)\&.
435 .PP
436 All of the
437 \(lq@\(rq
438 commands that can appear in place of the first five fields are extensions\&.
439 .SH "LIMITATIONS"
440 .PP
441 The
442 \fBcron\fR
443 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
444 \fITZ\fR
445 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:
446 .sp
447 .if n \{\
448 .RS 4
449 .\}
450 .nf
451 # m h dom mon dow command
452
453 TZ=UTC
454 0 * * * * [ "$(date +\e%R)" = 00:00 ] && run_some_script
455
456 .fi
457 .if n \{\
458 .RE
459 .\}
460 .PP
461 POSIX specifies that the day of month and the day of week fields both need to match the current time if either of them
462 \fIis\fR
463 a *\&. However, this implementation only checks if the
464 \fIfirst character\fR
465 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\&.
466 .PP
467 The
468 \fBcrontab\fR
469 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
470 \fIcrontab\fR
471 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\&.
472 .PP
473 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
474 \fBncal\fR(1)
475 or
476 \fBcalendar\fR(1)\&. For example, to run a program the last Saturday of every month you could use the following wrapper code:
477 .sp
478 .if n \{\
479 .RS 4
480 .\}
481 .nf
482 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
483
484 .fi
485 .if n \{\
486 .RE
487 .\}
488 .sp
489 .SH "USING EVAL TO WRAP MISC ENVIRONMENT SETTINGS"
490 .PP
491 The following tip is kindly provided by 積丹尼 Dan Jacobson:
492 .sp
493 .if n \{\
494 .RS 4
495 .\}
496 .nf
497 CONTENT_TYPE="text/plain; charset=UTF\-8"
498 d=eval LANG=zh_TW\&.UTF\-8 w3m \-dump
499 26 22 16 1\-12 * $d https://www\&.ptt\&.cc/bbs/transgender/index\&.html
500
501 .fi
502 .if n \{\
503 .RE
504 .\}
505 .PP
506 it won\*(Aqt work without the eval\&. Saying
507 .sp
508 .if n \{\
509 .RS 4
510 .\}
511 .nf
512 d=LANG=zh_TW\&.UTF\-8 w3m \-dump
513
514 .fi
515 .if n \{\
516 .RE
517 .\}
518 .PP
519 will get
520 .sp
521 .if n \{\
522 .RS 4
523 .\}
524 .nf
525 /bin/sh: LANG=zh_TW\&.UTF\-8: command not found
526
527 .fi
528 .if n \{\
529 .RE
530 .\}
531 .PP
532 .SH "DIAGNOSTICS"
533 .PP
534 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\&.
535 .SH "AUTHORS"
536 .PP
537 \fBPaul Vixie\fR <\&paul@vix\&.com\&>
538 .RS 4
539 Wrote this manpage (1994)\&.
540 .RE
541 .PP
542 \fBSteve Greenland\fR <\&stevegr@debian\&.org\&>
543 .RS 4
544 Maintained the package (1996\-2005)\&.
545 .RE
546 .PP
547 \fBJavier Fern\('andez\-Sanguino Pe\(~na\fR <\&jfs@debian\&.org\&>
548 .RS 4
549 Maintained the package (2005\-2014)\&.
550 .RE
551 .PP
552 \fBChristian Kastner\fR <\&ckk@debian\&.org\&>
553 .RS 4
554 Maintained the package (2010\-2016)\&.
555 .RE
556 .PP
557 \fBGeorges Khaznadar\fR <\&georgesk@debian\&.org\&>
558 .RS 4
559 Maintained the package (2022\-2024)\&.
560 .RE
561 .SH "COPYRIGHT"
562 .br
563 Copyright \(co 1994 Paul Vixie
564 .br
565 .PP
566 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\&.
567 .PP
568 Since year 1994, many modifications were made in this manpage, authored by Debian Developers which maintained
569 cron; above is a short list, more information can be found in the file
570 \fI/usr/share/doc/cron/copyright\fR\&.
571 .sp