xref: /openbsd-src/usr.sbin/cron/crontab.5 (revision 99fd087599a8791921855f21bd7e36130f39aadc)
1.\"/* Copyright 1988,1990,1993,1994 by Paul Vixie
2.\" * All rights reserved
3.\" */
4.\"
5.\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
6.\" Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
7.\"
8.\" Permission to use, copy, modify, and distribute this software for any
9.\" purpose with or without fee is hereby granted, provided that the above
10.\" copyright notice and this permission notice appear in all copies.
11.\"
12.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
13.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14.\" MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
15.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
18.\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19.\"
20.\" $OpenBSD: crontab.5,v 1.37 2020/01/06 19:44:09 job Exp $
21.\"
22.Dd $Mdocdate: January 6 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:
34.Dq at these times on these dates run this command .
35There may be a system
36.Nm
37and each user may have their own
38.Nm .
39Commands in any given
40.Nm
41will be
42executed either as the user who owns the
43.Nm
44or, in the case of the system
45.Nm crontab ,
46as the user specified on the command line.
47.Pp
48While a
49.Nm
50is a text file, it is not intended to be directly edited.
51Creation, modification, and removal of a
52.Nm
53should be done using
54.Xr crontab 1 .
55.Pp
56Blank lines, leading spaces, and tabs are ignored.
57Lines whose first non-space character is a pound sign
58.Pq Ql #
59are comments, and are ignored.
60Note that comments are not allowed on the same line as
61.Xr cron 8
62commands, since
63they will be taken to be part of the command.
64Similarly, comments are not
65allowed on the same line as environment variable settings.
66.Pp
67An active line in a
68.Nm
69is either an environment variable setting or a
70.Xr cron 8
71command.
72.Pp
73Environment variable settings create the environment
74any command in the
75.Nm
76is run in.
77An environment variable setting is of the form:
78.Pp
79.Dl name = value
80.Pp
81The spaces around the equal sign
82.Pq Ql =
83are optional, and any subsequent non-leading spaces in
84.Ar value
85will be part of the value assigned to
86.Ar name .
87The
88.Ar value
89string may be placed in quotes
90.Pq single or double , but matching
91to preserve leading or trailing blanks.
92.Pp
93Lines in the system
94.Nm
95have six fixed fields plus a command, in the form:
96.Bd -ragged -offset indent
97.Ar minute
98.Ar hour
99.Ar day-of-month
100.Ar month
101.Ar day-of-week
102.Ar user
103.Ar command
104.Ed
105.Pp
106While lines in a user
107.Nm
108have five fixed fields plus a command, in the form:
109.Bd -ragged -offset indent
110.Ar minute
111.Ar hour
112.Ar day-of-month
113.Ar month
114.Ar day-of-week
115.Ar command
116.Ed
117.Pp
118Fields are separated by blanks or tabs.
119The command may be one or more fields long.
120The allowed values for the fields are:
121.Bl -column "day-of-month" "allowed values" -offset indent
122.It Sy field Ta Sy allowed values
123.It Ar minute Ta * or 0\(en59
124.It Ar hour Ta * or 0\(en23
125.It Ar day-of-month Ta * or 1\(en31
126.It Ar month Ta * or 1\(en12 or a name (see below)
127.It Ar day-of-week Ta * or 0\(en7 or a name (0 or 7 is Sunday)
128.It Ar user Ta a valid username
129.It Ar command Ta text
130.El
131.Pp
132Lists are allowed.
133A list is a set of numbers (or ranges) separated by commas.
134For example,
135.Dq 1,2,5,9
136or
137.Dq 0\(en4,8\(en12 .
138.Pp
139Ranges of numbers are allowed.
140Ranges are two numbers separated with a hyphen.
141The specified range is inclusive.
142For example,
1438\(en11 for an
144.Ar hour
145entry specifies execution at hours 8, 9, 10 and 11.
146.Pp
147Step values can be used in conjunction with ranges.
148Following a range with
149.No / Ns Ar number
150specifies skips of
151.Ar number
152through the range.
153For example,
154.Dq 0\(en23/2
155can be used in the
156.Ar hour
157field to specify command execution every other hour.
158Steps are also permitted after an asterisk, so to say
159.Dq every two hours ,
160just use
161.Dq */2 .
162.Pp
163An asterisk
164.Pq Ql *
165is short form for a range of all allowed values.
166.Pp
167Names can be used in the
168.Ar month
169and
170.Ar day-of-week
171fields.
172Use the first three letters of the particular
173day or month (case doesn't matter).
174Ranges or lists of names are not allowed.
175.Pp
176The
177.Ar command
178field (the rest of the line) is the command to be
179run.
180The entire command portion of the line, up to a newline or %
181character, will be executed by
182.Pa /bin/sh
183or by the shell
184specified in the
185.Ev SHELL
186variable of the
187.Nm crontab .
188Percent signs
189.Pq Ql %
190in the command, unless escaped with a backslash
191.Pq Ql \e ,
192will be changed into newline characters, and all data
193after the first
194.Ql %
195will be sent to the command as standard input.
196.Pp
197Commands may be modified as follows:
198.Bl -tag -width Ds
199.It Fl n Ar command
200No mail is sent after a successful run.
201The execution output will only be mailed if the command exits with a non-zero
202exit code.
203The
204.Fl n
205option is an attempt to cure potentially copious volumes of mail coming from
206.Xr cron 8 .
207.It Fl q Ar command
208Execution will not be logged.
209.El
210.Pp
211Commands are executed by
212.Xr cron 8
213when the
214.Ar minute ,
215.Ar hour ,
216and
217.Ar month
218fields match the current time,
219.Em and
220when at least one of the two day fields
221.Po Ar day-of-month
222or
223.Ar day-of-week Pc ,
224match the current time.
225.Pp
226Note: The day of a command's execution can be specified by two
227fields \(em
228.Ar day-of-month
229and
230.Ar day-of-week .
231If both fields are restricted (i.e. aren't *),
232the command will be run when
233.Em either
234field matches the current time.
235For example,
236.Pp
237.Dl 30 4 1,15 * 5
238.Pp
239would cause a command to be run at 4:30 am on the 1st and 15th of each
240month, plus every Friday.
241.Pp
242Instead of the first five fields, one of eight special strings may appear:
243.Bl -column "@midnight" "meaning" -offset indent
244.It Sy string Ta Sy meaning
245.It @reboot Ta Run once, at startup.
246.It @yearly Ta Run every January 1 (0 0 1 1 *).
247.It @annually Ta The same as @yearly.
248.It @monthly Ta Run the first day of every month (0 0 1 * *).
249.It @weekly Ta Run every Sunday (0 0 * * 0).
250.It @daily Ta Run every midnight (0 0 * * *).
251.It @midnight Ta The same as @daily.
252.It @hourly Ta Run every hour, on the hour (0 * * * *).
253.El
254.Sh ENVIRONMENT
255.Bl -tag -width "LOGNAMEXXX"
256.It Ev HOME
257Set from the user's
258.Pa /etc/passwd
259entry.
260May be overridden by settings in the
261.Nm .
262.It Ev LOGNAME
263Set from the user's
264.Pa /etc/passwd
265entry.
266May not be overridden by settings in the
267.Nm .
268.It Ev MAILTO
269If
270.Ev MAILTO
271is defined and non-empty,
272mail is sent to the user so named.
273If
274.Ev MAILTO
275is defined but empty
276.Pq Ev MAILTO = Qq ,
277no mail will be sent.
278Otherwise mail is sent to the owner of the
279.Nm .
280This is useful for pseudo-users that lack an alias
281that would otherwise redirect the mail to a real person.
282.It Ev SHELL
283Set to
284.Pa /bin/sh .
285May be overridden by settings in the
286.Nm .
287.It Ev USER
288Set from the user's
289.Pa /etc/passwd
290entry.
291May not be overridden by settings in the
292.Nm .
293.El
294.Sh FILES
295.Bl -tag -width "/var/cron/tabs/<user>XXX" -compact
296.It Pa /etc/crontab
297System crontab.
298.It Pa /var/cron/tabs/ Ns Aq Ar user
299User crontab.
300.El
301.Sh EXAMPLES
302.Bd -literal
303# use /bin/sh to run commands, no matter what /etc/passwd says
304SHELL=/bin/sh
305# mail any output to `paul', no matter whose crontab this is
306MAILTO=paul
307#
308# run five minutes after midnight, every day
3095 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
310
311# run at 2:15pm on the first of every month -- job output will be sent
312# to paul, but only if $HOME/bin/monthly exits with a non-zero exit code
31315 14 1 * *     -n $HOME/bin/monthly
314
315# run at 10 pm on weekdays, annoy Joe
3160 22 * * 1-5	mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
317
31823 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
319
3205 4 * * sun     echo "run at 5 after 4 every sunday"
321.Ed
322.Sh SEE ALSO
323.Xr crontab 1 ,
324.Xr cron 8
325.Sh STANDARDS
326The
327.Nm
328file format is compliant with the
329.St -p1003.1-2008
330specification.
331The behaviours described below are all extensions to that standard:
332.Bl -dash
333.It
334The
335.Ar day-of-week
336field may use 7 to represent Sunday.
337.It
338Ranges may include
339.Dq steps .
340.It
341Months or days of the week can be specified by name.
342.It
343Mailing after a successful run can be suppressed with
344.Fl n .
345.It
346Logging can be suppressed with
347.Ql -q .
348.It
349Environment variables can be set in a crontab.
350.It
351Command output can be mailed to a person other than the crontab
352owner, or the feature can be turned off and no mail will be sent
353at all.
354.It
355All of the
356.Ql @
357commands that can appear in place of the first five fields.
358.El
359.Sh AUTHORS
360.Nm
361was written by
362.An Paul Vixie Aq Mt vixie@isc.org .
363