xref: /freebsd/usr.sbin/cron/crontab/crontab.5 (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
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 March 29, 2020
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.
154Each line has five time and date fields,
155followed by a user name
156(with optional ``:<group>'' and ``/<login-class>'' suffixes)
157if this is the system crontab file,
158followed by a command.
159Commands are executed by
160.Xr cron 8
161when the minute, hour, and month of year fields match the current time,
162.Em and
163when at least one of the two day fields (day of month, or day of week)
164matches the current time (see ``Note'' below).
165.Xr cron 8
166examines cron entries once every minute.
167The time and date fields are:
168.Bd -literal -offset indent
169field         allowed values
170-----         --------------
171minute        0-59
172hour          0-23
173day of month  1-31
174month         1-12 (or names, see below)
175day of week   0-7 (0 or 7 is Sun, or use names)
176.Ed
177.Pp
178A field may be an asterisk (*), which always stands for ``first\-last''.
179.Pp
180Ranges of numbers are allowed.
181Ranges are two numbers separated
182with a hyphen.
183The specified range is inclusive.
184For example,
1858-11 for an ``hours'' entry specifies execution at hours 8, 9, 10
186and 11.
187.Pp
188Lists are allowed.
189A list is a set of numbers (or ranges)
190separated by commas.
191Examples: ``1,2,5,9'', ``0-4,8-12''.
192.Pp
193Step values can be used in conjunction with ranges.
194Following
195a range with ``/<number>'' specifies skips of the number's value
196through the range.
197For example, ``0-23/2'' can be used in the hours
198field to specify command execution every other hour (the alternative
199in the V7 standard is ``0,2,4,6,8,10,12,14,16,18,20,22'').
200Steps are
201also permitted after an asterisk, so if you want to say ``every two
202hours'', just use ``*/2''.
203.Pp
204Names can also be used for the ``month'' and ``day of week''
205fields.
206Use the first three letters of the particular
207day or month (case does not matter).
208Ranges and lists are also allowed.
209.Pp
210The ``sixth'' field (the rest of the line) specifies the command to be
211run.
212One or more command options may precede the command to modify processing
213behavior.
214The entire command portion of the line, up to a newline or %
215character, will be executed by
216.Pa /bin/sh
217or by the shell
218specified in the
219.Ev SHELL
220variable of the cronfile.
221Percent-signs (%) in the command, unless escaped with backslash
222(\\), will be changed into newline characters, and all data
223after the first % will be sent to the command as standard
224input.
225.Pp
226The following command options can be supplied:
227.Bl -tag -width Ds
228.It Fl n
229No mail is sent after a successful run.
230The execution output will only be mailed if the command exits with a non-zero
231exit code.
232The
233.Fl n
234option is an attempt to cure potentially copious volumes of mail coming from
235.Xr cron 8 .
236.It Fl q
237Execution will not be logged.
238.El
239.sp
240Duplicate options are not allowed.
241.Pp
242Note: The day of a command's execution can be specified by two
243fields \(em day of month, and day of week.
244If both fields are
245restricted (ie, are not *), the command will be run when
246.Em either
247field matches the current time.
248For example,
249``30 4 1,15 * 5''
250would cause a command to be run at 4:30 am on the 1st and 15th of each
251month, plus every Friday.
252.Pp
253Instead of the first five fields,
254a line may start with
255.Sq @
256symbol followed either by one of eight special strings or by a numeric value.
257The recognized special strings are:
258.Bd -literal -offset indent
259string		meaning
260------		-------
261@reboot		Run once, at startup of cron.
262@yearly		Run once a year, "0 0 1 1 *".
263@annually	(same as @yearly)
264@monthly	Run once a month, "0 0 1 * *".
265@weekly		Run once a week, "0 0 * * 0".
266@daily		Run once a day, "0 0 * * *".
267@midnight	(same as @daily)
268@hourly		Run once an hour, "0 * * * *".
269@every_minute	Run once a minute, "*/1 * * * *".
270@every_second	Run once a second.
271.Ed
272.Pp
273The
274.Sq @
275symbol followed by a numeric value has a special notion of running
276a job that many seconds after completion of the previous invocation of
277the job.
278Unlike regular syntax, it guarantees not to overlap two or more
279invocations of the same job during normal cron execution.
280Note, however, that overlap may occur if the job is running when the file
281containing the job is modified and subsequently reloaded.
282The first run is scheduled for the specified number of seconds after cron
283is started or the crontab entry is reloaded.
284.Sh EXAMPLE CRON FILE
285.Bd -literal
286
287# use /bin/sh to run commands, overriding the default set by cron
288SHELL=/bin/sh
289# mail any output to `paul', no matter whose crontab this is
290MAILTO=paul
291#
292# run five minutes after midnight, every day
2935 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
294# run at 2:15pm on the first of every month -- output mailed to paul
29515 14 1 * *     $HOME/bin/monthly
296# run at 10 pm on weekdays, annoy Joe
2970 22 * * 1-5	mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
29823 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
2995 4 * * sun     echo "run at 5 after 4 every sunday"
300# run at 5 minutes intervals, no matter how long it takes
301@300		svnlite up /usr/src
302# run every minute, suppress logging
303* * * * *       -q date
304# run every minute, only send mail if ping fails
305* * * * *       -n ping -c 1 freebsd.org
306.Ed
307.Sh SEE ALSO
308.Xr crontab 1 ,
309.Xr cron 8
310.Sh EXTENSIONS
311When specifying day of week, both day 0 and day 7 will be considered Sunday.
312.Bx
313and
314.Tn ATT
315seem to disagree about this.
316.Pp
317Lists and ranges are allowed to co-exist in the same field.
318"1-3,7-9" would
319be rejected by
320.Tn ATT
321or
322.Bx
323cron -- they want to see "1-3" or "7,8,9" ONLY.
324.Pp
325Ranges can include "steps", so "1-9/2" is the same as "1,3,5,7,9".
326.Pp
327Names of months or days of the week can be specified by name.
328.Pp
329Environment variables can be set in the crontab.
330In
331.Bx
332or
333.Tn ATT ,
334the
335environment handed to child processes is basically the one from
336.Pa /etc/rc .
337.Pp
338Command output is mailed to the crontab owner
339.No ( Bx
340cannot do this), can be
341mailed to a person other than the crontab owner (SysV cannot do this), or the
342feature can be turned off and no mail will be sent at all (SysV cannot do this
343either).
344.Pp
345All of the
346.Sq @
347directives that can appear in place of the first five fields
348are extensions.
349.Pp
350Command processing can be modified using command options.
351The
352.Sq -q
353option suppresses logging.
354The
355.Sq -n
356option does not mail on successful run.
357.Sh AUTHORS
358.An Paul Vixie Aq Mt paul@vix.com
359.Sh BUGS
360If you are in one of the 70-odd countries that observe Daylight
361Savings Time, jobs scheduled during the rollback or advance may be
362affected if
363.Xr cron 8
364is not started with the
365.Fl s
366flag.
367In general, it is not a good idea to schedule jobs during
368this period if
369.Xr cron 8
370is not started with the
371.Fl s
372flag, which is enabled by default.
373See
374.Xr cron 8
375for more details.
376.Pp
377For US timezones (except parts of AZ and HI) the time shift occurs at
3782AM local time.
379For others, the output of the
380.Xr zdump 8
381program's verbose
382.Fl ( v )
383option can be used to determine the moment of time shift.
384