xref: /freebsd/usr.sbin/cron/crontab/crontab.5 (revision 7a7741af18d6c8a804cc643cb7ecda9d730c6aa6)
1.\"/* Copyright 1988,1990,1993,1994 by Paul Vixie
2.\" * All rights reserved
3.\" */
4.\"
5.\"Copyright (c) 1997 by Internet Software Consortium
6.\"
7.\"Permission to use, copy, modify, and distribute this software for any
8.\"purpose with or without fee is hereby granted, provided that the above
9.\"copyright notice and this permission notice appear in all copies.
10.\"
11.\"THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
12.\"ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
13.\"OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
14.\"CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15.\"DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
16.\"PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
17.\"ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
18.\"SOFTWARE.
19.\"
20.\" $Id: crontab.5,v 1.2 1998/08/14 00:32:38 vixie Exp $
21.\"
22.Dd May 10, 2024
23.Dt CRONTAB 5
24.Os
25.Sh NAME
26.Nm crontab
27.Nd tables for driving cron
28.Sh DESCRIPTION
29A
30.Nm
31file contains instructions to the
32.Xr cron 8
33daemon of the general form: ``run this command at this time on this date''.
34Each user has their own crontab, and commands in any given crontab will be
35executed as the user who owns the crontab.
36Uucp and News will usually have
37their own crontabs, eliminating the need for explicitly running
38.Xr su 1
39as part of a cron command.
40.Pp
41Blank lines and leading spaces and tabs are ignored.
42Lines whose first
43non-space character is a pound-sign (#) are comments, and are ignored.
44Note that comments are not allowed on the same line as cron commands, since
45they will be taken to be part of the command.
46Similarly, comments are not
47allowed on the same line as environment variable settings.
48.Pp
49An active line in a crontab will be either an environment setting or a cron
50command.
51An environment setting is of the form,
52.Bd -literal
53    name = value
54.Ed
55.Pp
56where the spaces around the equal-sign (=) are optional, and any subsequent
57non-leading spaces in
58.Em value
59will be part of the value assigned to
60.Em name .
61The
62.Em value
63string may be placed in quotes (single or double, but matching) to preserve
64leading or trailing blanks.
65The
66.Em name
67string may also be placed in quote (single or double, but matching)
68to preserve leading, trailing or inner blanks.
69.Pp
70Several environment variables are set up
71automatically by the
72.Xr cron 8
73daemon.
74.Ev SHELL
75is set to
76.Pa /bin/sh ,
77and
78.Ev LOGNAME
79and
80.Ev HOME
81are set from the
82.Pa /etc/passwd
83line of the crontab's owner.
84In addition, the environment variables of the
85user's login class will be set from
86.Pa /etc/login.conf.db
87and
88.Pa ~/.login_conf .
89(A setting of
90.Ev HOME
91in the login class will override the value from
92.Pa /etc/passwd ,
93but will not change the current directory when the command is
94invoked, which can only be overridden with an explicit setting of
95.Ev HOME
96within the crontab file itself.)
97If
98.Ev PATH
99is not set by any other means, it is defaulted to
100.Pa /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin .
101.Ev HOME ,
102.Ev PATH
103and
104.Ev SHELL ,
105and any variables set from the login class,
106may be overridden by settings in the crontab;
107.Ev LOGNAME
108may not.
109.Pp
110(Another note: the
111.Ev LOGNAME
112variable is sometimes called
113.Ev USER
114on
115.Bx
116systems...
117On these systems,
118.Ev USER
119will be set also).
120.Pp
121If
122.Xr cron 8
123has any reason to send mail as a result of running commands in
124``this'' crontab, it will respect the following settings which may be
125defined in the crontab (but which are not taken from the login class).
126If
127.Ev MAILTO
128is defined (and non-empty), mail is
129sent to the user so named.
130If
131.Ev MAILFROM
132is defined (and non-empty), its value will be used as the from address.
133.Ev MAILTO
134may also be used to direct mail to multiple recipients
135by separating recipient users with a comma.
136If
137.Ev MAILTO
138is defined but empty (MAILTO=""), no
139mail will be sent.
140Otherwise mail is sent to the owner of the crontab.
141This
142option is useful if you decide on
143.Pa /bin/mail
144instead of
145.Pa /usr/lib/sendmail
146as
147your mailer when you install cron --
148.Pa /bin/mail
149does not do aliasing, and UUCP
150usually does not read its mail.
151.Pp
152The format of a cron command is very much the V7 standard, with a number of
153upward-compatible extensions.
154.Pp
155Each user cron line has five time and date fields, followed by a command.
156.Pp
157Each line in system crontab (
158.Pa /etc/crontab, /etc/cron.d, /usr/local/etc/cron.d
159) has five time and date fields, followed by a valid user name
160(with optional ``:<group>'' and ``/<login-class>'' suffixes),
161followed by a command.
162.Pp
163Commands are executed by
164.Xr cron 8
165when the minute, hour, and month of year fields match the current time,
166.Em and
167when at least one of the two day fields (day of month, or day of week)
168matches the current time (see ``Note'' below).
169.Xr cron 8
170examines cron entries once every minute.
171The time and date fields are:
172.Bd -literal -offset indent
173field         allowed values
174-----         --------------
175minute        0-59
176hour          0-23
177day of month  1-31
178month         1-12 (or names, see below)
179day of week   0-7 (0 or 7 is Sun, or use names)
180.Ed
181.Pp
182A field may be an asterisk (*), which always stands for ``first\-last''.
183.Pp
184Ranges of numbers are allowed.
185Ranges are two numbers separated
186with a hyphen.
187The specified range is inclusive.
188For example,
1898-11 for an ``hours'' entry specifies execution at hours 8, 9, 10
190and 11.
191.Pp
192Lists are allowed.
193A list is a set of numbers (or ranges)
194separated by commas.
195Examples: ``1,2,5,9'', ``0-4,8-12''.
196.Pp
197Step values can be used in conjunction with ranges.
198Following
199a range with ``/<number>'' specifies skips of the number's value
200through the range.
201For example, ``0-23/2'' can be used in the hours
202field to specify command execution every other hour (the alternative
203in the V7 standard is ``0,2,4,6,8,10,12,14,16,18,20,22'').
204Steps are
205also permitted after an asterisk, so if you want to say ``every two
206hours'', just use ``*/2''.
207.Pp
208Names can also be used for the ``month'' and ``day of week''
209fields.
210Use the first three letters of the particular
211day or month (case does not matter).
212Ranges and lists are also allowed.
213.Pp
214The ``sixth'' field (the rest of the line) specifies the command to be
215run.
216One or more command options may precede the command to modify processing
217behavior.
218The entire command portion of the line, up to a newline or %
219character, will be executed by
220.Pa /bin/sh
221or by the shell
222specified in the
223.Ev SHELL
224variable of the cronfile.
225Percent-signs (%) in the command, unless escaped with backslash
226(\\), will be changed into newline characters, and all data
227after the first % will be sent to the command as standard
228input.
229.Pp
230The following command options can be supplied:
231.Bl -tag -width Ds
232.It Fl n
233No mail is sent after a successful run.
234The execution output will only be mailed if the command exits with a non-zero
235exit code.
236The
237.Fl n
238option is an attempt to cure potentially copious volumes of mail coming from
239.Xr cron 8 .
240.It Fl q
241Execution will not be logged.
242.El
243.sp
244Duplicate options are not allowed.
245.Pp
246Note: The day of a command's execution can be specified by two
247fields \(em day of month, and day of week.
248If both fields are
249restricted (ie, are not *), the command will be run when
250.Em either
251field matches the current time.
252For example,
253``30 4 1,15 * 5''
254would cause a command to be run at 4:30 am on the 1st and 15th of each
255month, plus every Friday.
256.Pp
257Instead of the first five fields,
258a line may start with
259.Sq @
260symbol followed either by one of eight special strings or by a numeric value.
261The recognized special strings are:
262.Bd -literal -offset indent
263string		meaning
264------		-------
265@reboot		Run once, at startup of cron.
266@yearly		Run once a year, "0 0 1 1 *".
267@annually	(same as @yearly)
268@monthly	Run once a month, "0 0 1 * *".
269@weekly		Run once a week, "0 0 * * 0".
270@daily		Run once a day, "0 0 * * *".
271@midnight	(same as @daily)
272@hourly		Run once an hour, "0 * * * *".
273@every_minute	Run once a minute, "*/1 * * * *".
274@every_second	Run once a second.
275.Ed
276.Pp
277The
278.Sq @
279symbol followed by a numeric value has a special notion of running
280a job that many seconds after completion of the previous invocation of
281the job.
282Unlike regular syntax, it guarantees not to overlap two or more
283invocations of the same job during normal cron execution.
284Note, however, that overlap may occur if the job is running when the file
285containing the job is modified and subsequently reloaded.
286The first run is scheduled for the specified number of seconds after cron
287is started or the crontab entry is reloaded.
288.Sh EXAMPLE SYSTEM CRON FILE
289.Bd -literal
290# sample /etc/cron.d/vmstat
291# run vmstat every five minutes
292# note the username as sixth field!
293*/5 * * * * root vmstat
294.Ed
295.Sh EXAMPLE USER CRON FILE
296.Bd -literal
297# use /bin/sh to run commands, overriding the default set by cron
298SHELL=/bin/sh
299# mail any output to `paul', no matter whose crontab this is
300MAILTO=paul
301#
302# run five minutes after midnight, every day
3035 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
304# run at 2:15pm on the first of every month -- output mailed to paul
30515 14 1 * *     $HOME/bin/monthly
306# run at 10 pm on weekdays, annoy Joe
3070 22 * * 1-5	mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
30823 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
3095 4 * * sun     echo "run at 5 after 4 every sunday"
310# run at 5 minutes intervals, no matter how long it takes
311@300		svnlite up /usr/src
312# run every minute, suppress logging
313* * * * *       -q date
314# run every minute, only send mail if ping fails
315* * * * *       -n ping -c 1 freebsd.org
316.Ed
317.Sh SEE ALSO
318.Xr crontab 1 ,
319.Xr cron 8
320.Sh EXTENSIONS
321When specifying day of week, both day 0 and day 7 will be considered Sunday.
322.Bx
323and
324.Tn ATT
325seem to disagree about this.
326.Pp
327Lists and ranges are allowed to co-exist in the same field.
328"1-3,7-9" would
329be rejected by
330.Tn ATT
331or
332.Bx
333cron -- they want to see "1-3" or "7,8,9" ONLY.
334.Pp
335Ranges can include "steps", so "1-9/2" is the same as "1,3,5,7,9".
336.Pp
337Names of months or days of the week can be specified by name.
338.Pp
339Environment variables can be set in the crontab.
340In
341.Bx
342or
343.Tn ATT ,
344the
345environment handed to child processes is basically the one from
346.Pa /etc/rc .
347.Pp
348Command output is mailed to the crontab owner
349.No ( Bx
350cannot do this), can be
351mailed to a person other than the crontab owner (SysV cannot do this), or the
352feature can be turned off and no mail will be sent at all (SysV cannot do this
353either).
354.Pp
355All of the
356.Sq @
357directives that can appear in place of the first five fields
358are extensions.
359.Pp
360Command processing can be modified using command options.
361The
362.Sq -q
363option suppresses logging.
364The
365.Sq -n
366option does not mail on successful run.
367.Sh AUTHORS
368.An Paul Vixie Aq Mt paul@vix.com
369.Sh BUGS
370If you are in one of the 70-odd countries that observe Daylight
371Savings Time, jobs scheduled during the rollback or advance may be
372affected if
373.Xr cron 8
374is not started with the
375.Fl s
376flag.
377In general, it is not a good idea to schedule jobs during
378this period if
379.Xr cron 8
380is not started with the
381.Fl s
382flag, which is enabled by default.
383See
384.Xr cron 8
385for more details.
386.Pp
387For US timezones (except parts of AZ and HI) the time shift occurs at
3882AM local time.
389For others, the output of the
390.Xr zdump 8
391program's verbose
392.Fl ( v )
393option can be used to determine the moment of time shift.
394