xref: /freebsd/usr.sbin/cron/crontab/crontab.5 (revision fd522d40d80136173d2bd35b8f47107dce5f570e)
184f33deaSJordan K. Hubbard.\"/* Copyright 1988,1990,1993,1994 by Paul Vixie
284f33deaSJordan K. Hubbard.\" * All rights reserved
384f33deaSJordan K. Hubbard.\" *
484f33deaSJordan K. Hubbard.\" * Distribute freely, except: don't remove my name from the source or
584f33deaSJordan K. Hubbard.\" * documentation (don't take credit for my work), mark your changes (don't
684f33deaSJordan K. Hubbard.\" * get me blamed for your possible bugs), don't alter or remove this
784f33deaSJordan K. Hubbard.\" * notice.  May be sold if buildable source is provided to buyer.  No
884f33deaSJordan K. Hubbard.\" * warrantee of any kind, express or implied, is included with this
984f33deaSJordan K. Hubbard.\" * software; use at your own risk, responsibility for damages (if any) to
1084f33deaSJordan K. Hubbard.\" * anyone resulting from the use of this software rests entirely with the
1184f33deaSJordan K. Hubbard.\" * user.
1284f33deaSJordan K. Hubbard.\" *
1384f33deaSJordan K. Hubbard.\" * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
1484f33deaSJordan K. Hubbard.\" * I'll try to keep a version up to date.  I can be reached as follows:
1584f33deaSJordan K. Hubbard.\" * Paul Vixie          <paul@vix.com>          uunet!decwrl!vixie!paul
1684f33deaSJordan K. Hubbard.\" */
1784f33deaSJordan K. Hubbard.\"
1897d92980SPeter Wemm.\" $FreeBSD$
1984f33deaSJordan K. Hubbard.\"
20401e6468SPhilippe Charnier.Dd January 24, 1994
21401e6468SPhilippe Charnier.Dt CRONTAB 5
22401e6468SPhilippe Charnier.Os
23401e6468SPhilippe Charnier.Sh NAME
24401e6468SPhilippe Charnier.Nm crontab
25401e6468SPhilippe Charnier.Nd tables for driving cron
26401e6468SPhilippe Charnier.Sh DESCRIPTION
2784f33deaSJordan K. HubbardA
28401e6468SPhilippe Charnier.Nm
2984f33deaSJordan K. Hubbardfile contains instructions to the
30401e6468SPhilippe Charnier.Xr cron 8
3184f33deaSJordan K. Hubbarddaemon of the general form: ``run this command at this time on this date''.
3284f33deaSJordan K. HubbardEach user has their own crontab, and commands in any given crontab will be
3384f33deaSJordan K. Hubbardexecuted as the user who owns the crontab.  Uucp and News will usually have
3484f33deaSJordan K. Hubbardtheir own crontabs, eliminating the need for explicitly running
35401e6468SPhilippe Charnier.Xr su 1
3684f33deaSJordan K. Hubbardas part of a cron command.
37401e6468SPhilippe Charnier.Pp
3884f33deaSJordan K. HubbardBlank lines and leading spaces and tabs are ignored.  Lines whose first
3984f33deaSJordan K. Hubbardnon-space character is a pound-sign (#) are comments, and are ignored.
4084f33deaSJordan K. HubbardNote that comments are not allowed on the same line as cron commands, since
4184f33deaSJordan K. Hubbardthey will be taken to be part of the command.  Similarly, comments are not
4284f33deaSJordan K. Hubbardallowed on the same line as environment variable settings.
43401e6468SPhilippe Charnier.Pp
4484f33deaSJordan K. HubbardAn active line in a crontab will be either an environment setting or a cron
4584f33deaSJordan K. Hubbardcommand.  An environment setting is of the form,
46c5083414SRuslan Ermilov.Bd -literal
4784f33deaSJordan K. Hubbard    name = value
48c5083414SRuslan Ermilov.Ed
49401e6468SPhilippe Charnier.Pp
5084f33deaSJordan K. Hubbardwhere the spaces around the equal-sign (=) are optional, and any subsequent
5184f33deaSJordan K. Hubbardnon-leading spaces in
52401e6468SPhilippe Charnier.Em value
5384f33deaSJordan K. Hubbardwill be part of the value assigned to
54401e6468SPhilippe Charnier.Em name .
5584f33deaSJordan K. HubbardThe
56401e6468SPhilippe Charnier.Em value
5784f33deaSJordan K. Hubbardstring may be placed in quotes (single or double, but matching) to preserve
5884f33deaSJordan K. Hubbardleading or trailing blanks.
59c3e1da6bSSheldon HearnThe
60c3e1da6bSSheldon Hearn.Em name
61c3e1da6bSSheldon Hearnstring may also be placed in quote (single or double, but matching)
62c3e1da6bSSheldon Hearnto preserve leading, traling or inner blanks.
63401e6468SPhilippe Charnier.Pp
6484f33deaSJordan K. HubbardSeveral environment variables are set up
6584f33deaSJordan K. Hubbardautomatically by the
66401e6468SPhilippe Charnier.Xr cron 8
6784f33deaSJordan K. Hubbarddaemon.
68401e6468SPhilippe Charnier.Ev SHELL
69401e6468SPhilippe Charnieris set to
70401e6468SPhilippe Charnier.Pa /bin/sh ,
71401e6468SPhilippe Charnierand
72401e6468SPhilippe Charnier.Ev LOGNAME
73401e6468SPhilippe Charnierand
74401e6468SPhilippe Charnier.Ev HOME
75401e6468SPhilippe Charnierare set from the
76401e6468SPhilippe Charnier.Pa /etc/passwd
7784f33deaSJordan K. Hubbardline of the crontab's owner.
78401e6468SPhilippe Charnier.Ev HOME
79401e6468SPhilippe Charnierand
80401e6468SPhilippe Charnier.Ev SHELL
81401e6468SPhilippe Charniermay be overridden by settings in the crontab;
82401e6468SPhilippe Charnier.Ev LOGNAME
83401e6468SPhilippe Charniermay not.
84401e6468SPhilippe Charnier.Pp
85401e6468SPhilippe Charnier(Another note: the
86401e6468SPhilippe Charnier.Ev LOGNAME
87401e6468SPhilippe Charniervariable is sometimes called
88401e6468SPhilippe Charnier.Ev USER
89401e6468SPhilippe Charnieron BSD systems...
90401e6468SPhilippe Charnieron these systems,
91401e6468SPhilippe Charnier.Ev USER
92401e6468SPhilippe Charnierwill be set also).
93401e6468SPhilippe Charnier.Pp
94401e6468SPhilippe CharnierIn addition to
95401e6468SPhilippe Charnier.Ev LOGNAME ,
96401e6468SPhilippe Charnier.Ev HOME ,
97401e6468SPhilippe Charnierand
98401e6468SPhilippe Charnier.Ev SHELL ,
99401e6468SPhilippe Charnier.Xr cron 8
100401e6468SPhilippe Charnierwill look at
101401e6468SPhilippe Charnier.Ev MAILTO
102401e6468SPhilippe Charnierif it has any reason to send mail as a result of running
103401e6468SPhilippe Charniercommands in ``this'' crontab.  If
104401e6468SPhilippe Charnier.Ev MAILTO
105401e6468SPhilippe Charnieris defined (and non-empty), mail is
106401e6468SPhilippe Charniersent to the user so named.  If
107401e6468SPhilippe Charnier.Ev MAILTO
108401e6468SPhilippe Charnieris defined but empty (MAILTO=""), no
10984f33deaSJordan K. Hubbardmail will be sent.  Otherwise mail is sent to the owner of the crontab.  This
110401e6468SPhilippe Charnieroption is useful if you decide on
111401e6468SPhilippe Charnier.Pa /bin/mail
112401e6468SPhilippe Charnierinstead of
113401e6468SPhilippe Charnier.Pa /usr/lib/sendmail
114401e6468SPhilippe Charnieras
115401e6468SPhilippe Charnieryour mailer when you install cron --
116401e6468SPhilippe Charnier.Pa /bin/mail
117401e6468SPhilippe Charnierdoesn't do aliasing, and UUCP
11884f33deaSJordan K. Hubbardusually doesn't read its mail.
119401e6468SPhilippe Charnier.Pp
12084f33deaSJordan K. HubbardThe format of a cron command is very much the V7 standard, with a number of
12184f33deaSJordan K. Hubbardupward-compatible extensions.  Each line has five time and date fields,
1220435c150SAndrey A. Chernovfollowed by a user name
1230435c150SAndrey A. Chernov(with optional ``:<group>'' and ``/<login-class>'' suffixes)
1240435c150SAndrey A. Chernovif this is the system crontab file,
12584f33deaSJordan K. Hubbardfollowed by a command.  Commands are executed by
126401e6468SPhilippe Charnier.Xr cron 8
12784f33deaSJordan K. Hubbardwhen the minute, hour, and month of year fields match the current time,
128401e6468SPhilippe Charnier.Em and
12984f33deaSJordan K. Hubbardwhen at least one of the two day fields (day of month, or day of week)
13084f33deaSJordan K. Hubbardmatch the current time (see ``Note'' below).
131401e6468SPhilippe Charnier.Xr cron 8
13284f33deaSJordan K. Hubbardexamines cron entries once every minute.
13384f33deaSJordan K. HubbardThe time and date fields are:
134401e6468SPhilippe Charnier.Bd -literal -offset indent
13584f33deaSJordan K. Hubbardfield         allowed values
13684f33deaSJordan K. Hubbard-----         --------------
13784f33deaSJordan K. Hubbardminute        0-59
13884f33deaSJordan K. Hubbardhour          0-23
139043c578eSMike Pritchardday of month  1-31
140043c578eSMike Pritchardmonth         1-12 (or names, see below)
14184f33deaSJordan K. Hubbardday of week   0-7 (0 or 7 is Sun, or use names)
142401e6468SPhilippe Charnier.Ed
143401e6468SPhilippe Charnier.Pp
14484f33deaSJordan K. HubbardA field may be an asterisk (*), which always stands for ``first\-last''.
145401e6468SPhilippe Charnier.Pp
14684f33deaSJordan K. HubbardRanges of numbers are allowed.  Ranges are two numbers separated
14784f33deaSJordan K. Hubbardwith a hyphen.  The specified range is inclusive.  For example,
14884f33deaSJordan K. Hubbard8-11 for an ``hours'' entry specifies execution at hours 8, 9, 10
14984f33deaSJordan K. Hubbardand 11.
150401e6468SPhilippe Charnier.Pp
15184f33deaSJordan K. HubbardLists are allowed.  A list is a set of numbers (or ranges)
15284f33deaSJordan K. Hubbardseparated by commas.  Examples: ``1,2,5,9'', ``0-4,8-12''.
153401e6468SPhilippe Charnier.Pp
15484f33deaSJordan K. HubbardStep values can be used in conjunction with ranges.  Following
15584f33deaSJordan K. Hubbarda range with ``/<number>'' specifies skips of the number's value
15684f33deaSJordan K. Hubbardthrough the range.  For example, ``0-23/2'' can be used in the hours
15784f33deaSJordan K. Hubbardfield to specify command execution every other hour (the alternative
15884f33deaSJordan K. Hubbardin the V7 standard is ``0,2,4,6,8,10,12,14,16,18,20,22'').  Steps are
15984f33deaSJordan K. Hubbardalso permitted after an asterisk, so if you want to say ``every two
16084f33deaSJordan K. Hubbardhours'', just use ``*/2''.
161401e6468SPhilippe Charnier.Pp
16284f33deaSJordan K. HubbardNames can also be used for the ``month'' and ``day of week''
16384f33deaSJordan K. Hubbardfields.  Use the first three letters of the particular
16484f33deaSJordan K. Hubbardday or month (case doesn't matter).  Ranges or
16584f33deaSJordan K. Hubbardlists of names are not allowed.
166401e6468SPhilippe Charnier.Pp
16784f33deaSJordan K. HubbardThe ``sixth'' field (the rest of the line) specifies the command to be
16884f33deaSJordan K. Hubbardrun.
16984f33deaSJordan K. HubbardThe entire command portion of the line, up to a newline or %
170401e6468SPhilippe Charniercharacter, will be executed by
171401e6468SPhilippe Charnier.Pa /bin/sh
172401e6468SPhilippe Charnieror by the shell
173401e6468SPhilippe Charnierspecified in the
174401e6468SPhilippe Charnier.Ev SHELL
175401e6468SPhilippe Charniervariable of the cronfile.
17684f33deaSJordan K. HubbardPercent-signs (%) in the command, unless escaped with backslash
17784f33deaSJordan K. Hubbard(\\), will be changed into newline characters, and all data
17884f33deaSJordan K. Hubbardafter the first % will be sent to the command as standard
17984f33deaSJordan K. Hubbardinput.
180401e6468SPhilippe Charnier.Pp
18184f33deaSJordan K. HubbardNote: The day of a command's execution can be specified by two
18284f33deaSJordan K. Hubbardfields \(em day of month, and day of week.  If both fields are
18384f33deaSJordan K. Hubbardrestricted (ie, aren't *), the command will be run when
184401e6468SPhilippe Charnier.Em either
18584f33deaSJordan K. Hubbardfield matches the current time.  For example,
18684f33deaSJordan K. Hubbard``30 4 1,15 * 5''
18784f33deaSJordan K. Hubbardwould cause a command to be run at 4:30 am on the 1st and 15th of each
18884f33deaSJordan K. Hubbardmonth, plus every Friday.
189c3e1da6bSSheldon Hearn.Pp
190c3e1da6bSSheldon HearnInstead of the first five fields,
191c3e1da6bSSheldon Hearnone of eight special strings may appear:
192c3e1da6bSSheldon Hearn.Bd -literal -offset indent
193c3e1da6bSSheldon Hearnstring		meaning
194c3e1da6bSSheldon Hearn------		-------
195c3e1da6bSSheldon Hearn@reboot		Run once, at startup.
196c3e1da6bSSheldon Hearn@yearly		Run once a year, "0 0 1 1 *".
197fd522d40SBill Fumerola@annually	(same as @yearly)
198c3e1da6bSSheldon Hearn@monthly	Run once a month, "0 0 1 * *".
199c3e1da6bSSheldon Hearn@weekly		Run once a week, "0 0 * * 0".
200c3e1da6bSSheldon Hearn@daily		Run once a day, "0 0 * * *".
201c3e1da6bSSheldon Hearn@midnight	(same as @daily)
202c3e1da6bSSheldon Hearn@hourly		Run once an hour, "0 * * * *".
203c3e1da6bSSheldon Hearn.Ed
204401e6468SPhilippe Charnier.Sh EXAMPLE CRON FILE
205401e6468SPhilippe Charnier.Bd -literal
20684f33deaSJordan K. Hubbard
207d2a864e4SNick Hibma# use /bin/sh to run commands, overriding the default set by cron
20884f33deaSJordan K. HubbardSHELL=/bin/sh
20984f33deaSJordan K. Hubbard# mail any output to `paul', no matter whose crontab this is
21084f33deaSJordan K. HubbardMAILTO=paul
21184f33deaSJordan K. Hubbard#
21284f33deaSJordan K. Hubbard# run five minutes after midnight, every day
21384f33deaSJordan K. Hubbard5 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
21484f33deaSJordan K. Hubbard# run at 2:15pm on the first of every month -- output mailed to paul
21584f33deaSJordan K. Hubbard15 14 1 * *     $HOME/bin/monthly
21684f33deaSJordan K. Hubbard# run at 10 pm on weekdays, annoy Joe
21784f33deaSJordan K. Hubbard0 22 * * 1-5	mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
21884f33deaSJordan K. Hubbard23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
21984f33deaSJordan K. Hubbard5 4 * * sun     echo "run at 5 after 4 every sunday"
220401e6468SPhilippe Charnier.Ed
221401e6468SPhilippe Charnier.Sh SEE ALSO
222bf5cbf35SWolfram Schneider.Xr crontab 1 ,
223bf5cbf35SWolfram Schneider.Xr cron 8
224401e6468SPhilippe Charnier.Sh EXTENSIONS
22584f33deaSJordan K. HubbardWhen specifying day of week, both day 0 and day 7 will be considered Sunday.
22684f33deaSJordan K. HubbardBSD and ATT seem to disagree about this.
227401e6468SPhilippe Charnier.Pp
22884f33deaSJordan K. HubbardLists and ranges are allowed to co-exist in the same field.  "1-3,7-9" would
22984f33deaSJordan K. Hubbardbe rejected by ATT or BSD cron -- they want to see "1-3" or "7,8,9" ONLY.
230401e6468SPhilippe Charnier.Pp
23184f33deaSJordan K. HubbardRanges can include "steps", so "1-9/2" is the same as "1,3,5,7,9".
232401e6468SPhilippe Charnier.Pp
23384f33deaSJordan K. HubbardNames of months or days of the week can be specified by name.
234401e6468SPhilippe Charnier.Pp
23584f33deaSJordan K. HubbardEnvironment variables can be set in the crontab.  In BSD or ATT, the
236401e6468SPhilippe Charnierenvironment handed to child processes is basically the one from
237401e6468SPhilippe Charnier.Pa /etc/rc .
238401e6468SPhilippe Charnier.Pp
23984f33deaSJordan K. HubbardCommand output is mailed to the crontab owner (BSD can't do this), can be
24084f33deaSJordan K. Hubbardmailed to a person other than the crontab owner (SysV can't do this), or the
24184f33deaSJordan K. Hubbardfeature can be turned off and no mail will be sent at all (SysV can't do this
24284f33deaSJordan K. Hubbardeither).
243c3e1da6bSSheldon Hearn.Pp
244c3e1da6bSSheldon HearnAll of the
245c3e1da6bSSheldon Hearn.Sq @
246c3e1da6bSSheldon Hearncommands that can appear in place of the first five fields
247c3e1da6bSSheldon Hearnare extensions.
248f12a1471SPhilippe Charnier.Sh AUTHORS
249401e6468SPhilippe Charnier.An Paul Vixie Aq paul@vix.com
25081f4b036SSheldon Hearn.Sh BUGS
25181f4b036SSheldon HearnIf you're in one of the 70-odd countries that observe Daylight
25281f4b036SSheldon HearnSavings Time, jobs scheduled during the rollback or advance will be
25381f4b036SSheldon Hearnaffected.  In general, it's not a good idea to schedule jobs during
25481f4b036SSheldon Hearnthis period.
25581f4b036SSheldon Hearn.Pp
25681f4b036SSheldon HearnFor US timezones (except parts of IN, AZ, and HI) the time shift occurs at
25781f4b036SSheldon Hearn2AM local time.  For others, the output of the
25881f4b036SSheldon Hearn.Xr zdump 8
25981f4b036SSheldon Hearnprogram's verbose
26081f4b036SSheldon Hearn.Fl ( v )
26181f4b036SSheldon Hearnoption can be used to determine the moment of time shift.
262