xref: /netbsd-src/external/bsd/cron/dist/crontab.5 (revision fe40cc28997ae921447bee65cf44cc8c5dd3e0a8)
1*fe40cc28Schristos.\" $NetBSD: crontab.5,v 1.11 2022/02/26 17:02:47 christos Exp $
2032a4398Schristos.\"
30061c6a5Schristos.\"/* Copyright 1988,1990,1993,1994 by Paul Vixie
40061c6a5Schristos.\" * All rights reserved
50061c6a5Schristos.\" */
60061c6a5Schristos.\"
749111522Schristos.\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
849111522Schristos.\" Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
90061c6a5Schristos.\"
1049111522Schristos.\" Permission to use, copy, modify, and distribute this software for any
1149111522Schristos.\" purpose with or without fee is hereby granted, provided that the above
1249111522Schristos.\" copyright notice and this permission notice appear in all copies.
1349111522Schristos.\"
1449111522Schristos.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
1549111522Schristos.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1649111522Schristos.\" MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
1749111522Schristos.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1849111522Schristos.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1949111522Schristos.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
2049111522Schristos.\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2149111522Schristos.\"
2249111522Schristos.\" $OpenBSD: crontab.5,v 1.36 2018/06/13 13:27:37 jmc Exp $
2349111522Schristos.\"
24*fe40cc28Schristos.Dd February 26, 2022
25032a4398Schristos.Dt CRONTAB 5
26032a4398Schristos.Os
27032a4398Schristos.Sh NAME
28032a4398Schristos.Nm crontab
29032a4398Schristos.Nd tables for driving cron
30032a4398Schristos.Sh DESCRIPTION
310061c6a5SchristosA
32032a4398Schristos.Nm
330061c6a5Schristosfile contains instructions to the
34032a4398Schristos.Xr cron 8
35032a4398Schristosdaemon of the general form:
3649111522Schristos.Dq at these times on these dates run this command .
3749111522SchristosThere may be a system
3849111522Schristos.Nm
3949111522Schristosand each user may have their own
4049111522Schristos.Nm .
4149111522SchristosCommands in any given
4249111522Schristos.Nm
4349111522Schristoswill be
4449111522Schristosexecuted either as the user who owns the
4549111522Schristos.Nm
4649111522Schristosor, in the case of the system
4749111522Schristos.Nm crontab ,
4849111522Schristosas the user specified on the command line.
49032a4398Schristos.Pp
5049111522SchristosWhile a
5149111522Schristos.Nm
5249111522Schristosis a text file, it is not intended to be directly edited.
5349111522SchristosCreation, modification, and removal of a
5449111522Schristos.Nm
5549111522Schristosshould be done using
5649111522Schristos.Xr crontab 1 .
5749111522Schristos.Pp
5849111522SchristosBlank lines, leading spaces, and tabs are ignored.
5949111522SchristosLines whose first non-space character is a pound sign
6049111522Schristos.Pq Ql #
61032a4398Schristosare comments, and are ignored.
6249111522SchristosNote that comments are not allowed on the same line as
6349111522Schristos.Xr cron 8
6449111522Schristoscommands, since
65032a4398Schristosthey will be taken to be part of the command.
66032a4398SchristosSimilarly, comments are not
670061c6a5Schristosallowed on the same line as environment variable settings.
68032a4398Schristos.Pp
6949111522SchristosAn active line in a
7049111522Schristos.Nm
7149111522Schristosis either an environment variable setting or a
7249111522Schristos.Xr cron 8
7349111522Schristoscommand.
7449111522Schristos.Pp
7549111522SchristosEnvironment variable settings create the environment
7649111522Schristosany command in the
7749111522Schristos.Nm
7849111522Schristosis run in.
7949111522SchristosAn environment variable setting is of the form:
8049111522Schristos.Pp
8149111522Schristos.Dl name = value
8249111522Schristos.Pp
8349111522SchristosThe spaces around the equal sign
8449111522Schristos.Pq Ql =
85032a4398Schristosare optional, and any subsequent non-leading spaces in
86032a4398Schristos.Ar value
870061c6a5Schristoswill be part of the value assigned to
88032a4398Schristos.Ar name .
890061c6a5SchristosThe
90032a4398Schristos.Ar value
9149111522Schristosstring may be placed in quotes
9249111522Schristos.Pq single or double , but matching
9349111522Schristosto preserve leading or trailing blanks.
9449111522Schristos.Pp
9549111522SchristosLines in the system
9649111522Schristos.Nm
9749111522Schristoshave six fixed fields plus a command, in the form:
9849111522Schristos.Bd -ragged -offset indent
9949111522Schristos.Ar minute
10049111522Schristos.Ar hour
10149111522Schristos.Ar day-of-month
10249111522Schristos.Ar month
10349111522Schristos.Ar day-of-week
10449111522Schristos.Ar user
10549111522Schristos.Ar command
10649111522Schristos.Ed
10749111522Schristos.Pp
10849111522SchristosWhile lines in a user
10949111522Schristos.Nm
11049111522Schristoshave five fixed fields plus a command, in the form:
11149111522Schristos.Bd -ragged -offset indent
11249111522Schristos.Ar minute
11349111522Schristos.Ar hour
11449111522Schristos.Ar day-of-month
11549111522Schristos.Ar month
11649111522Schristos.Ar day-of-week
11749111522Schristos.Ar command
11849111522Schristos.Ed
11949111522Schristos.Pp
12049111522SchristosFields are separated by blanks or tabs.
12149111522SchristosThe command may be one or more fields long.
12249111522SchristosThe allowed values for the fields are:
12349111522Schristos.Bl -column "day-of-month" "allowed values" -offset indent
12449111522Schristos.It Sy field Ta Sy allowed values
12549111522Schristos.It Ar minute Ta * or 0\(en59
12649111522Schristos.It Ar hour Ta * or 0\(en23
12749111522Schristos.It Ar day-of-month Ta * or 1\(en31
12849111522Schristos.It Ar month Ta * or 1\(en12 or a name (see below)
12949111522Schristos.It Ar day-of-week Ta * or 0\(en7 or a name (0 or 7 is Sunday)
13049111522Schristos.It Ar user Ta a valid username
13149111522Schristos.It Ar command Ta text
13249111522Schristos.El
13349111522Schristos.Pp
13449111522SchristosLists are allowed.
13549111522SchristosA list is a set of numbers (or ranges) separated by commas.
13649111522SchristosFor example,
13749111522Schristos.Dq 1,2,5,9
13849111522Schristosor
13949111522Schristos.Dq 0\(en4,8\(en12 .
14049111522Schristos.Pp
14149111522SchristosRanges of numbers are allowed.
14249111522SchristosRanges are two numbers separated with a hyphen.
14349111522SchristosThe specified range is inclusive.
1444e06cde2SpgoyetteFor example,
1454e06cde2Spgoyette8\(en11 for an
1464e06cde2Spgoyette.Ar hour
1474e06cde2Spgoyetteentry specifies execution at hours 8, 9, 10 and 11.
148685ba05bSchristos.Pp
149685ba05bSchristosA field may begin with a question mark
150685ba05bSchristos.Pq Sq \&? ,
151685ba05bSchristoswhich indicates a single value randomly selected when the crontab
152685ba05bSchristosfile is read.
153685ba05bSchristosIf the field contains only a question mark, the value is randomly
154685ba05bSchristosselected from the range of all possible values for the field.
155685ba05bSchristosIf the question mark precedes a range, the value is randomly selected
156685ba05bSchristosfrom the range.
157685ba05bSchristosFor example,
158685ba05bSchristos.Dq ? ?2-5 * * *
159685ba05bSchristosspecifies that a task will be performed daily between 2:00am and
160685ba05bSchristosand 5:59am at a time randomly selected when the crontab file is
161685ba05bSchristosfirst read.
162685ba05bSchristosAs just one example, this feature can be used to prevent a large
163685ba05bSchristosnumber of hosts from contacting a server simultaneously and
164685ba05bSchristosoverloading it by staggering the time at which a download script
165685ba05bSchristosis executed.
16649111522Schristos.Pp
167685ba05bSchristosStep values can be used in conjunction with ranges (but not random ranges
168685ba05bSchristoswhich represent a single number).
16949111522SchristosFollowing a range with
17049111522Schristos.No / Ns Ar number
17149111522Schristosspecifies skips of
17249111522Schristos.Ar number
17349111522Schristosthrough the range.
17449111522SchristosFor example,
17549111522Schristos.Dq 0\(en23/2
17649111522Schristoscan be used in the
17749111522Schristos.Ar hour
17849111522Schristosfield to specify command execution every other hour.
17949111522SchristosSteps are also permitted after an asterisk, so to say
18049111522Schristos.Dq every two hours ,
18149111522Schristosjust use
18249111522Schristos.Dq */2 .
18349111522Schristos.Pp
18449111522SchristosAn asterisk
18549111522Schristos.Pq Ql *
18649111522Schristosis short form for a range of all allowed values.
18749111522Schristos.Pp
18849111522SchristosNames can be used in the
18949111522Schristos.Ar month
19049111522Schristosand
19149111522Schristos.Ar day-of-week
19249111522Schristosfields.
19349111522SchristosUse the first three letters of the particular
19449111522Schristosday or month (case doesn't matter).
19549111522SchristosRanges or lists of names are not allowed.
19649111522Schristos.Pp
197032a4398SchristosThe
19849111522Schristos.Ar command
19949111522Schristosfield (the rest of the line) is the command to be
20049111522Schristosrun.
20149111522SchristosThe entire command portion of the line, up to a newline or %
20249111522Schristoscharacter, will be executed by
20349111522Schristos.Pa /bin/sh
20449111522Schristosor by the shell
20549111522Schristosspecified in the
206032a4398Schristos.Ev SHELL
20749111522Schristosvariable of the
20849111522Schristos.Nm crontab .
20949111522SchristosPercent signs
21049111522Schristos.Pq Ql %
21149111522Schristosin the command, unless escaped with a backslash
21249111522Schristos.Pq Ql \e ,
21349111522Schristoswill be changed into newline characters, and all data
21449111522Schristosafter the first
21549111522Schristos.Ql %
21649111522Schristoswill be sent to the command as standard input.
217032a4398Schristos.Pp
21849111522SchristosCommands may be modified as follows:
21949111522Schristos.Bl -tag -width Ds
22049111522Schristos.It Fl n Ar command
22149111522SchristosNo mail is sent after a successful run.
22249111522SchristosThe execution output will only be mailed if the command exits with a non-zero
22349111522Schristosexit code.
22449111522SchristosThe
22549111522Schristos.Fl n
22649111522Schristosoption is an attempt to cure potentially copious volumes of mail coming from
22749111522Schristos.Xr cron 8 .
22849111522Schristos.It Fl q Ar command
22949111522SchristosExecution will not be logged.
230cd115652Schristos.It Fl s Ar command
231cd115652SchristosOnly a single instance of
232cd115652Schristos.Ar command
233cd115652Schristoswill be run concurrently.
234cd115652SchristosAdditional instances of
235cd115652Schristos.Ar command
236cd115652Schristoswill not be scheduled until the earlier one completes.
23749111522Schristos.El
238032a4398Schristos.Pp
23949111522SchristosCommands are executed by
240032a4398Schristos.Xr cron 8
24149111522Schristoswhen the
24249111522Schristos.Ar minute ,
24349111522Schristos.Ar hour ,
244032a4398Schristosand
24549111522Schristos.Ar month
24649111522Schristosfields match the current time,
24749111522Schristos.Em and
24849111522Schristoswhen at least one of the two day fields
24949111522Schristos.Po Ar day-of-month
25049111522Schristosor
25149111522Schristos.Ar day-of-week Pc ,
25249111522Schristosmatch the current time.
25349111522Schristos.Pp
25449111522SchristosNote: The day of a command's execution can be specified by two
25549111522Schristosfields \(em
25649111522Schristos.Ar day-of-month
25749111522Schristosand
25849111522Schristos.Ar day-of-week .
25949111522SchristosIf both fields are restricted (i.e. aren't *),
26049111522Schristosthe command will be run when
26149111522Schristos.Em either
26249111522Schristosfield matches the current time.
26349111522SchristosFor example,
26449111522Schristos.Pp
26549111522Schristos.Dl 30 4 1,15 * 5
26649111522Schristos.Pp
26749111522Schristoswould cause a command to be run at 4:30 am on the 1st and 15th of each
26849111522Schristosmonth, plus every Friday.
26949111522Schristos.Pp
27049111522SchristosInstead of the first five fields, one of eight special strings may appear:
27149111522Schristos.Bl -column "@midnight" "meaning" -offset indent
27249111522Schristos.It Sy string Ta Sy meaning
27349111522Schristos.It @reboot Ta Run once, at startup.
27449111522Schristos.It @yearly Ta Run every January 1 (0 0 1 1 *).
27549111522Schristos.It @annually Ta The same as @yearly.
27649111522Schristos.It @monthly Ta Run the first day of every month (0 0 1 * *).
27749111522Schristos.It @weekly Ta Run every Sunday (0 0 * * 0).
27849111522Schristos.It @daily Ta Run every midnight (0 0 * * *).
27949111522Schristos.It @midnight Ta The same as @daily.
28049111522Schristos.It @hourly Ta Run every hour, on the hour (0 * * * *).
28149111522Schristos.El
28249111522Schristos.Sh ENVIRONMENT
28349111522Schristos.Bl -tag -width "CRON_WITHIN"
28449111522Schristos.It Ev CRON_TZ
285032a4398SchristosThe
286032a4398Schristos.Ev CRON_TZ
28749111522Schristosvariable can be set to an alternate time zone in order to affect when the job
28849111522Schristosis run.
28949111522SchristosNote that this only affects the scheduling of the job, not the time zone
29049111522Schristosthat the job perceives when it is run.
291032a4398SchristosIf
292032a4398Schristos.Ev CRON_TZ
293032a4398Schristosis defined but empty
294032a4398Schristos.Pq Ev CRON_TZ Ns = Ns \&"" ,
295032a4398Schristosjobs are scheduled with respect to the local time zone.
29649111522Schristos.It Ev CRON_WITHIN
297032a4398SchristosThe
298032a4398Schristos.Ev CRON_WITHIN
299032a4398Schristosvariable should indicate the number of seconds within a job's
300032a4398Schristosscheduled time that it should still be run.
301*fe40cc28SchristosFor example if a job is scheduled for 12:30pm and
302*fe40cc28Schristos.Ev CRON_WITHIN
303*fe40cc28Schristosis
304*fe40cc28Schristos.Dv 120
305*fe40cc28Schristos(2 minutes), then the job will not be run if the system attempts
306*fe40cc28Schristosto start it past 12:32pm.
307032a4398SchristosOn a heavily loaded system, or on a system that has just been
308032a4398Schristos.Dq woken up ,
309032a4398Schristosjobs will sometimes start later than originally intended, and by
310032a4398Schristosskipping non-critical jobs because of delays, system load can be
311032a4398Schristoslightened.
312032a4398SchristosIf
313032a4398Schristos.Ev CRON_WITHIN
314032a4398Schristosis defined but empty
31549111522Schristos.Pq Ev CRON_WITHIN Ns = Ns \&"" ,
316032a4398Schristosor set to some non-positive value (0, a negative number, or a
317*fe40cc28Schristosnon-numeric string), it is treated as if it was unset, that is
318*fe40cc28Schristosthe job will always run, even if it is going to start at a time
319*fe40cc28Schristoslong past its scheduled time.
32049111522Schristos.It Ev HOME
32149111522SchristosSet from the user's
32249111522Schristos.Pa /etc/passwd
32349111522Schristosentry.
32449111522SchristosMay be overridden by settings in the
32549111522Schristos.Nm .
32649111522Schristos.It Ev LOGNAME
32749111522SchristosSet from the user's
32849111522Schristos.Pa /etc/passwd
32949111522Schristosentry.
33049111522SchristosMay not be overridden by settings in the
33149111522Schristos.Nm .
33249111522Schristos.It Ev MAILTO
33349111522SchristosIf
33449111522Schristos.Ev MAILTO
33549111522Schristosis defined and non-empty,
33649111522Schristosmail is sent to the user so named.
33749111522SchristosIf
33849111522Schristos.Ev MAILTO
33949111522Schristosis defined but empty
34049111522Schristos.Pq Ev MAILTO = Qq ,
34149111522Schristosno mail will be sent.
34249111522SchristosOtherwise mail is sent to the owner of the
34349111522Schristos.Nm .
34449111522SchristosThis is useful for pseudo-users that lack an alias
34549111522Schristosthat would otherwise redirect the mail to a real person.
34649111522Schristos.It Ev SHELL
34749111522SchristosSet to
34849111522Schristos.Pa /bin/sh .
34949111522SchristosMay be overridden by settings in the
35049111522Schristos.Nm .
35149111522Schristos.It Ev USER
35249111522SchristosSet from the user's
35349111522Schristos.Pa /etc/passwd
35449111522Schristosentry.
35549111522SchristosMay not be overridden by settings in the
35649111522Schristos.Nm .
357032a4398Schristos.El
35849111522Schristos.Sh FILES
35949111522Schristos.Bl -tag -width "/var/cron/tabs/<user>XXX" -compact
36049111522Schristos.It Pa /etc/crontab
36149111522SchristosSystem crontab.
36249111522Schristos.It Pa /var/cron/tabs/ Ns Aq Ar user
36349111522SchristosUser crontab.
364032a4398Schristos.El
36549111522Schristos.Sh EXAMPLES
366032a4398Schristos.Bd -literal
3670061c6a5Schristos# use /bin/sh to run commands, no matter what /etc/passwd says
3680061c6a5SchristosSHELL=/bin/sh
3690061c6a5Schristos# mail any output to `paul', no matter whose crontab this is
3700061c6a5SchristosMAILTO=paul
3710061c6a5Schristos#
3720061c6a5Schristos# run five minutes after midnight, every day
37349111522Schristos5 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
3740061c6a5Schristos# run at 2:15pm on the first of every month -- output mailed to paul
3750061c6a5Schristos15 14 1 * *     $HOME/bin/monthly
3760061c6a5Schristos# run at 10 pm on weekdays, annoy Joe
3770061c6a5Schristos0 22 * * 1-5	mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
3780061c6a5Schristos23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
3790061c6a5Schristos5 4 * * sun     echo "run at 5 after 4 every sunday"
380032a4398Schristos.Ed
381032a4398Schristos.Sh SEE ALSO
382032a4398Schristos.Xr crontab 1 ,
383032a4398Schristos.Xr cron 8
384032a4398Schristos.Sh STANDARDS
38549111522SchristosThe
38649111522Schristos.Nm
38749111522Schristosfile format is compliant with the
38849111522Schristos.St -p1003.1-2008
38949111522Schristosspecification.
39049111522SchristosThe behaviours described below are all extensions to that standard:
39149111522Schristos.Bl -dash
39249111522Schristos.It
39349111522SchristosThe
39449111522Schristos.Ar day-of-week
39549111522Schristosfield may use 7 to represent Sunday.
39649111522Schristos.It
39749111522SchristosRanges may include
39849111522Schristos.Dq steps .
39949111522Schristos.It
40049111522SchristosMonths or days of the week can be specified by name.
40149111522Schristos.It
40249111522SchristosMailing after a successful run can be suppressed with
40349111522Schristos.Fl n .
40449111522Schristos.It
40549111522SchristosLogging can be suppressed with
40649111522Schristos.Fl q .
40749111522Schristos.It
40849111522SchristosEnvironment variables can be set in a crontab.
40949111522Schristos.It
41049111522SchristosCommand output can be mailed to a person other than the crontab
41149111522Schristosowner, or the feature can be turned off and no mail will be sent
41249111522Schristosat all.
41349111522Schristos.It
414032a4398SchristosAll of the
41549111522Schristos.Ql @
41649111522Schristoscommands that can appear in place of the first five fields.
41749111522Schristos.El
418032a4398Schristos.Sh AUTHORS
41949111522Schristos.Nm
42049111522Schristoswas written by
42149111522Schristos.An Paul Vixie Aq Mt vixie@isc.org .
422