xref: /freebsd/usr.sbin/cron/crontab/crontab.5 (revision 07bfccd71e05867cb46c11ea07ec0027794972b3)
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
3307bfccd7SRuslan Ermilovexecuted as the user who owns the crontab.
3407bfccd7SRuslan ErmilovUucp and News will usually have
3584f33deaSJordan K. Hubbardtheir own crontabs, eliminating the need for explicitly running
36401e6468SPhilippe Charnier.Xr su 1
3784f33deaSJordan K. Hubbardas part of a cron command.
38401e6468SPhilippe Charnier.Pp
3907bfccd7SRuslan ErmilovBlank lines and leading spaces and tabs are ignored.
4007bfccd7SRuslan ErmilovLines whose first
4184f33deaSJordan K. Hubbardnon-space character is a pound-sign (#) are comments, and are ignored.
4284f33deaSJordan K. HubbardNote that comments are not allowed on the same line as cron commands, since
4307bfccd7SRuslan Ermilovthey will be taken to be part of the command.
4407bfccd7SRuslan ErmilovSimilarly, comments are not
4584f33deaSJordan K. Hubbardallowed on the same line as environment variable settings.
46401e6468SPhilippe Charnier.Pp
4784f33deaSJordan K. HubbardAn active line in a crontab will be either an environment setting or a cron
4807bfccd7SRuslan Ermilovcommand.
4907bfccd7SRuslan ErmilovAn environment setting is of the form,
50c5083414SRuslan Ermilov.Bd -literal
5184f33deaSJordan K. Hubbard    name = value
52c5083414SRuslan Ermilov.Ed
53401e6468SPhilippe Charnier.Pp
5484f33deaSJordan K. Hubbardwhere the spaces around the equal-sign (=) are optional, and any subsequent
5584f33deaSJordan K. Hubbardnon-leading spaces in
56401e6468SPhilippe Charnier.Em value
5784f33deaSJordan K. Hubbardwill be part of the value assigned to
58401e6468SPhilippe Charnier.Em name .
5984f33deaSJordan K. HubbardThe
60401e6468SPhilippe Charnier.Em value
6184f33deaSJordan K. Hubbardstring may be placed in quotes (single or double, but matching) to preserve
6284f33deaSJordan K. Hubbardleading or trailing blanks.
63c3e1da6bSSheldon HearnThe
64c3e1da6bSSheldon Hearn.Em name
65c3e1da6bSSheldon Hearnstring may also be placed in quote (single or double, but matching)
6657bd0fc6SJens Schweikhardtto preserve leading, trailing or inner blanks.
67401e6468SPhilippe Charnier.Pp
6884f33deaSJordan K. HubbardSeveral environment variables are set up
6984f33deaSJordan K. Hubbardautomatically by the
70401e6468SPhilippe Charnier.Xr cron 8
7184f33deaSJordan K. Hubbarddaemon.
72401e6468SPhilippe Charnier.Ev SHELL
73401e6468SPhilippe Charnieris set to
74401e6468SPhilippe Charnier.Pa /bin/sh ,
75401e6468SPhilippe Charnierand
76401e6468SPhilippe Charnier.Ev LOGNAME
77401e6468SPhilippe Charnierand
78401e6468SPhilippe Charnier.Ev HOME
79401e6468SPhilippe Charnierare set from the
80401e6468SPhilippe Charnier.Pa /etc/passwd
8184f33deaSJordan K. Hubbardline of the crontab's owner.
82401e6468SPhilippe Charnier.Ev HOME
83401e6468SPhilippe Charnierand
84401e6468SPhilippe Charnier.Ev SHELL
85401e6468SPhilippe Charniermay be overridden by settings in the crontab;
86401e6468SPhilippe Charnier.Ev LOGNAME
87401e6468SPhilippe Charniermay not.
88401e6468SPhilippe Charnier.Pp
89401e6468SPhilippe Charnier(Another note: the
90401e6468SPhilippe Charnier.Ev LOGNAME
91401e6468SPhilippe Charniervariable is sometimes called
92401e6468SPhilippe Charnier.Ev USER
93753d686dSRuslan Ermilovon
94753d686dSRuslan Ermilov.Bx
95753d686dSRuslan Ermilovsystems...
96c75526d5SRuslan ErmilovOn these systems,
97401e6468SPhilippe Charnier.Ev USER
98401e6468SPhilippe Charnierwill be set also).
99401e6468SPhilippe Charnier.Pp
100401e6468SPhilippe CharnierIn addition to
101401e6468SPhilippe Charnier.Ev LOGNAME ,
102401e6468SPhilippe Charnier.Ev HOME ,
103401e6468SPhilippe Charnierand
104401e6468SPhilippe Charnier.Ev SHELL ,
105401e6468SPhilippe Charnier.Xr cron 8
106401e6468SPhilippe Charnierwill look at
107401e6468SPhilippe Charnier.Ev MAILTO
108401e6468SPhilippe Charnierif it has any reason to send mail as a result of running
10907bfccd7SRuslan Ermilovcommands in ``this'' crontab.
11007bfccd7SRuslan ErmilovIf
111401e6468SPhilippe Charnier.Ev MAILTO
112401e6468SPhilippe Charnieris defined (and non-empty), mail is
1138030199cSTom Rhodessent to the user so named.
1148030199cSTom Rhodes.Ev MAILTO
1158030199cSTom Rhodesmay also be used to direct mail to multiple recipients
1168030199cSTom Rhodesby seperating recipient users with a comma.
1178030199cSTom RhodesIf
118401e6468SPhilippe Charnier.Ev MAILTO
119401e6468SPhilippe Charnieris defined but empty (MAILTO=""), no
12007bfccd7SRuslan Ermilovmail will be sent.
12107bfccd7SRuslan ErmilovOtherwise mail is sent to the owner of the crontab.
12207bfccd7SRuslan ErmilovThis
123401e6468SPhilippe Charnieroption is useful if you decide on
124401e6468SPhilippe Charnier.Pa /bin/mail
125401e6468SPhilippe Charnierinstead of
126401e6468SPhilippe Charnier.Pa /usr/lib/sendmail
127401e6468SPhilippe Charnieras
128401e6468SPhilippe Charnieryour mailer when you install cron --
129401e6468SPhilippe Charnier.Pa /bin/mail
130401e6468SPhilippe Charnierdoesn't do aliasing, and UUCP
13184f33deaSJordan K. Hubbardusually doesn't read its mail.
132401e6468SPhilippe Charnier.Pp
13384f33deaSJordan K. HubbardThe format of a cron command is very much the V7 standard, with a number of
13407bfccd7SRuslan Ermilovupward-compatible extensions.
13507bfccd7SRuslan ErmilovEach line has five time and date fields,
1360435c150SAndrey A. Chernovfollowed by a user name
1370435c150SAndrey A. Chernov(with optional ``:<group>'' and ``/<login-class>'' suffixes)
1380435c150SAndrey A. Chernovif this is the system crontab file,
13907bfccd7SRuslan Ermilovfollowed by a command.
14007bfccd7SRuslan ErmilovCommands are executed by
141401e6468SPhilippe Charnier.Xr cron 8
14284f33deaSJordan K. Hubbardwhen the minute, hour, and month of year fields match the current time,
143401e6468SPhilippe Charnier.Em and
14484f33deaSJordan K. Hubbardwhen at least one of the two day fields (day of month, or day of week)
1454188e025SGiorgos Keramidasmatches the current time (see ``Note'' below).
146401e6468SPhilippe Charnier.Xr cron 8
14784f33deaSJordan K. Hubbardexamines cron entries once every minute.
14884f33deaSJordan K. HubbardThe time and date fields are:
149401e6468SPhilippe Charnier.Bd -literal -offset indent
15084f33deaSJordan K. Hubbardfield         allowed values
15184f33deaSJordan K. Hubbard-----         --------------
15284f33deaSJordan K. Hubbardminute        0-59
15384f33deaSJordan K. Hubbardhour          0-23
154043c578eSMike Pritchardday of month  1-31
155043c578eSMike Pritchardmonth         1-12 (or names, see below)
15684f33deaSJordan K. Hubbardday of week   0-7 (0 or 7 is Sun, or use names)
157401e6468SPhilippe Charnier.Ed
158401e6468SPhilippe Charnier.Pp
15984f33deaSJordan K. HubbardA field may be an asterisk (*), which always stands for ``first\-last''.
160401e6468SPhilippe Charnier.Pp
16107bfccd7SRuslan ErmilovRanges of numbers are allowed.
16207bfccd7SRuslan ErmilovRanges are two numbers separated
16307bfccd7SRuslan Ermilovwith a hyphen.
16407bfccd7SRuslan ErmilovThe specified range is inclusive.
16507bfccd7SRuslan ErmilovFor example,
16684f33deaSJordan K. Hubbard8-11 for an ``hours'' entry specifies execution at hours 8, 9, 10
16784f33deaSJordan K. Hubbardand 11.
168401e6468SPhilippe Charnier.Pp
16907bfccd7SRuslan ErmilovLists are allowed.
17007bfccd7SRuslan ErmilovA list is a set of numbers (or ranges)
17107bfccd7SRuslan Ermilovseparated by commas.
17207bfccd7SRuslan ErmilovExamples: ``1,2,5,9'', ``0-4,8-12''.
173401e6468SPhilippe Charnier.Pp
17407bfccd7SRuslan ErmilovStep values can be used in conjunction with ranges.
17507bfccd7SRuslan ErmilovFollowing
17684f33deaSJordan K. Hubbarda range with ``/<number>'' specifies skips of the number's value
17707bfccd7SRuslan Ermilovthrough the range.
17807bfccd7SRuslan ErmilovFor example, ``0-23/2'' can be used in the hours
17984f33deaSJordan K. Hubbardfield to specify command execution every other hour (the alternative
18007bfccd7SRuslan Ermilovin the V7 standard is ``0,2,4,6,8,10,12,14,16,18,20,22'').
18107bfccd7SRuslan ErmilovSteps are
18284f33deaSJordan K. Hubbardalso permitted after an asterisk, so if you want to say ``every two
18384f33deaSJordan K. Hubbardhours'', just use ``*/2''.
184401e6468SPhilippe Charnier.Pp
18584f33deaSJordan K. HubbardNames can also be used for the ``month'' and ``day of week''
18607bfccd7SRuslan Ermilovfields.
18707bfccd7SRuslan ErmilovUse the first three letters of the particular
18807bfccd7SRuslan Ermilovday or month (case doesn't matter).
18907bfccd7SRuslan ErmilovRanges or
19084f33deaSJordan K. Hubbardlists of names are not allowed.
191401e6468SPhilippe Charnier.Pp
19284f33deaSJordan K. HubbardThe ``sixth'' field (the rest of the line) specifies the command to be
19384f33deaSJordan K. Hubbardrun.
19484f33deaSJordan K. HubbardThe entire command portion of the line, up to a newline or %
195401e6468SPhilippe Charniercharacter, will be executed by
196401e6468SPhilippe Charnier.Pa /bin/sh
197401e6468SPhilippe Charnieror by the shell
198401e6468SPhilippe Charnierspecified in the
199401e6468SPhilippe Charnier.Ev SHELL
200401e6468SPhilippe Charniervariable of the cronfile.
20184f33deaSJordan K. HubbardPercent-signs (%) in the command, unless escaped with backslash
20284f33deaSJordan K. Hubbard(\\), will be changed into newline characters, and all data
20384f33deaSJordan K. Hubbardafter the first % will be sent to the command as standard
20484f33deaSJordan K. Hubbardinput.
205401e6468SPhilippe Charnier.Pp
20684f33deaSJordan K. HubbardNote: The day of a command's execution can be specified by two
20707bfccd7SRuslan Ermilovfields \(em day of month, and day of week.
20807bfccd7SRuslan ErmilovIf both fields are
20984f33deaSJordan K. Hubbardrestricted (ie, aren't *), the command will be run when
210401e6468SPhilippe Charnier.Em either
21107bfccd7SRuslan Ermilovfield matches the current time.
21207bfccd7SRuslan ErmilovFor example,
21384f33deaSJordan K. Hubbard``30 4 1,15 * 5''
21484f33deaSJordan K. Hubbardwould cause a command to be run at 4:30 am on the 1st and 15th of each
21584f33deaSJordan K. Hubbardmonth, plus every Friday.
216c3e1da6bSSheldon Hearn.Pp
217c3e1da6bSSheldon HearnInstead of the first five fields,
218c3e1da6bSSheldon Hearnone of eight special strings may appear:
219c3e1da6bSSheldon Hearn.Bd -literal -offset indent
220c3e1da6bSSheldon Hearnstring		meaning
221c3e1da6bSSheldon Hearn------		-------
222c3e1da6bSSheldon Hearn@reboot		Run once, at startup.
223c3e1da6bSSheldon Hearn@yearly		Run once a year, "0 0 1 1 *".
224fd522d40SBill Fumerola@annually	(same as @yearly)
225c3e1da6bSSheldon Hearn@monthly	Run once a month, "0 0 1 * *".
226c3e1da6bSSheldon Hearn@weekly		Run once a week, "0 0 * * 0".
227c3e1da6bSSheldon Hearn@daily		Run once a day, "0 0 * * *".
228c3e1da6bSSheldon Hearn@midnight	(same as @daily)
229c3e1da6bSSheldon Hearn@hourly		Run once an hour, "0 * * * *".
230c3e1da6bSSheldon Hearn.Ed
231401e6468SPhilippe Charnier.Sh EXAMPLE CRON FILE
232401e6468SPhilippe Charnier.Bd -literal
23384f33deaSJordan K. Hubbard
234d2a864e4SNick Hibma# use /bin/sh to run commands, overriding the default set by cron
23584f33deaSJordan K. HubbardSHELL=/bin/sh
23684f33deaSJordan K. Hubbard# mail any output to `paul', no matter whose crontab this is
23784f33deaSJordan K. HubbardMAILTO=paul
23884f33deaSJordan K. Hubbard#
23984f33deaSJordan K. Hubbard# run five minutes after midnight, every day
24084f33deaSJordan K. Hubbard5 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
24184f33deaSJordan K. Hubbard# run at 2:15pm on the first of every month -- output mailed to paul
24284f33deaSJordan K. Hubbard15 14 1 * *     $HOME/bin/monthly
24384f33deaSJordan K. Hubbard# run at 10 pm on weekdays, annoy Joe
24484f33deaSJordan K. Hubbard0 22 * * 1-5	mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
24584f33deaSJordan K. Hubbard23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
24684f33deaSJordan K. Hubbard5 4 * * sun     echo "run at 5 after 4 every sunday"
247401e6468SPhilippe Charnier.Ed
248401e6468SPhilippe Charnier.Sh SEE ALSO
249bf5cbf35SWolfram Schneider.Xr crontab 1 ,
250bf5cbf35SWolfram Schneider.Xr cron 8
251401e6468SPhilippe Charnier.Sh EXTENSIONS
25284f33deaSJordan K. HubbardWhen specifying day of week, both day 0 and day 7 will be considered Sunday.
253753d686dSRuslan Ermilov.Bx
254753d686dSRuslan Ermilovand
255753d686dSRuslan Ermilov.Tn ATT
256753d686dSRuslan Ermilovseem to disagree about this.
257401e6468SPhilippe Charnier.Pp
25807bfccd7SRuslan ErmilovLists and ranges are allowed to co-exist in the same field.
25907bfccd7SRuslan Ermilov"1-3,7-9" would
260753d686dSRuslan Ermilovbe rejected by
261753d686dSRuslan Ermilov.Tn ATT
262753d686dSRuslan Ermilovor
263753d686dSRuslan Ermilov.Bx
264753d686dSRuslan Ermilovcron -- they want to see "1-3" or "7,8,9" ONLY.
265401e6468SPhilippe Charnier.Pp
26684f33deaSJordan K. HubbardRanges can include "steps", so "1-9/2" is the same as "1,3,5,7,9".
267401e6468SPhilippe Charnier.Pp
26884f33deaSJordan K. HubbardNames of months or days of the week can be specified by name.
269401e6468SPhilippe Charnier.Pp
27007bfccd7SRuslan ErmilovEnvironment variables can be set in the crontab.
27107bfccd7SRuslan ErmilovIn
272753d686dSRuslan Ermilov.Bx
273753d686dSRuslan Ermilovor
274753d686dSRuslan Ermilov.Tn ATT ,
275753d686dSRuslan Ermilovthe
276401e6468SPhilippe Charnierenvironment handed to child processes is basically the one from
277401e6468SPhilippe Charnier.Pa /etc/rc .
278401e6468SPhilippe Charnier.Pp
279753d686dSRuslan ErmilovCommand output is mailed to the crontab owner
280753d686dSRuslan Ermilov.No ( Bx
281753d686dSRuslan Ermilovcan't do this), can be
28284f33deaSJordan K. Hubbardmailed to a person other than the crontab owner (SysV can't do this), or the
28384f33deaSJordan K. Hubbardfeature can be turned off and no mail will be sent at all (SysV can't do this
28484f33deaSJordan K. Hubbardeither).
285c3e1da6bSSheldon Hearn.Pp
286c3e1da6bSSheldon HearnAll of the
287c3e1da6bSSheldon Hearn.Sq @
288c3e1da6bSSheldon Hearncommands that can appear in place of the first five fields
289c3e1da6bSSheldon Hearnare extensions.
290f12a1471SPhilippe Charnier.Sh AUTHORS
291401e6468SPhilippe Charnier.An Paul Vixie Aq paul@vix.com
29281f4b036SSheldon Hearn.Sh BUGS
29381f4b036SSheldon HearnIf you're in one of the 70-odd countries that observe Daylight
29481f4b036SSheldon HearnSavings Time, jobs scheduled during the rollback or advance will be
29507bfccd7SRuslan Ermilovaffected.
29607bfccd7SRuslan ErmilovIn general, it's not a good idea to schedule jobs during
29781f4b036SSheldon Hearnthis period.
29881f4b036SSheldon Hearn.Pp
29981f4b036SSheldon HearnFor US timezones (except parts of IN, AZ, and HI) the time shift occurs at
30007bfccd7SRuslan Ermilov2AM local time.
30107bfccd7SRuslan ErmilovFor others, the output of the
30281f4b036SSheldon Hearn.Xr zdump 8
30381f4b036SSheldon Hearnprogram's verbose
30481f4b036SSheldon Hearn.Fl ( v )
30581f4b036SSheldon Hearnoption can be used to determine the moment of time shift.
306