Added extra/crond.service for systemd
[dcron.git] / crontab.1
blob36043a943f452881b2c60d464e7310d2c6b68864
1 .TH CRONTAB 1 "1 May 2011"
2 .SH NAME
3 .PP
4 crontab - manipulate per-user crontabs (dillon's lightweight cron
5 daemon)
6 .SH SYNOPSIS
7 .PP
8 \f[B]crontab file [-u user]\f[] - replace crontab from file
9 .PP
10 \f[B]crontab - [-u user]\f[] - replace crontab from stdin
11 .PP
12 \f[B]crontab -l [-u user]\f[] - list crontab for user
13 .PP
14 \f[B]crontab -e [-u user]\f[] - edit crontab for user
15 .PP
16 \f[B]crontab -d [-u user]\f[] - delete crontab for user
17 .PP
18 \f[B]crontab -c dir\f[] - specify crontab directory
19 .SH DESCRIPTION
20 .PP
21 \f[B]crontab\f[] manipulates the per-user crontabs.
22 .PP
23 Generally the -e option is used to edit your crontab.
24 \f[B]crontab\f[] will use the editor specified by your EDITOR or
25 VISUAL environment variable (or /usr/bin/vi) to edit the crontab.
26 .PP
27 \f[B]crontab\f[] doesn't provide the kinds of protections that
28 programs like \f[B]visudo\f[] do against syntax errors and
29 simultaneous edits.
30 Errors won't be detected until \f[B]crond\f[] reads the crontab
31 file.
32 What \f[B]crontab\f[] does is provide a mechanism for users who may
33 not themselves have write privileges to the crontab folder to
34 nonetheless install or edit their crontabs.
35 It also notifies a running crond daemon of any changes to these
36 files.
37 .PP
38 Only users who belong to the same group as the \f[B]crontab\f[]
39 binary will be able to install or edit crontabs.
40 However it'll be possible for the superuser to install crontabs
41 even for users who don't have the privileges to install them
42 themselves.
43 (Even for users who don't have a login shell.)
44 Only the superuser may use the -u or -c switches to specify a
45 different user and/or crontab directory.
46 .PP
47 The superuser also has his or her own per-user crontab, saved as
48 /var/spool/cron/crontabs/root.
49 .PP
50 Unlike other cron daemons, this crond/crontab package doesn't try
51 to do everything under the sun.
52 It doesn't try to keep track of user's preferred shells; that would
53 require special-casing users with no login shell.
54 Instead, it just runs all commands using \f[C]/bin/sh\f[].
55 (Commands can of course be script files written in any shell you
56 like.)
57 .PP
58 Nor does it do any special environment handling.
59 A shell script is better-suited to doing that than a cron daemon.
60 This cron daemon sets up only four environment variables: USER,
61 LOGNAME, HOME, and SHELL.
62 .PP
63 Our crontab format is roughly similar to that used by vixiecron.
64 Individual fields may contain a time, a time range, a time range
65 with a skip factor, a symbolic range for the day of week and month
66 in year, and additional subranges delimited with commas.
67 Blank lines in the crontab or lines that begin with a hash (#) are
68 ignored.
69 If you specify both a day in the month and a day of week, it will
70 be interpreted as the Nth such day in the month.
71 .PP
72 Some examples:
73 .IP
74 .nf
75 \f[C]
76 #\ MIN\ HOUR\ DAY\ MONTH\ DAYOFWEEK\ \ COMMAND
77 #\ run\ `date`\ at\ 6:10\ am\ every\ day
78 10\ 6\ *\ *\ *\ date
80 #\ run\ every\ two\ hours\ at\ the\ top\ of\ the\ hour
81 0\ */2\ *\ *\ *\ date
83 #\ run\ every\ two\ hours\ between\ 11\ pm\ and\ 7\ am,\ and\ again\ at\ 8\ am
84 0\ 23-7/2,8\ *\ *\ *\ date
86 #\ run\ at\ 4:00\ am\ on\ January\ 1st
87 0\ 4\ 1\ jan\ *\ date
89 #\ run\ every\ day\ at\ 11\ am,\ appending\ all\ output\ to\ a\ file
90 0\ 11\ *\ *\ *\ date\ >>\ /var/log/date-output\ 2>&1
91 \f[]
92 .fi
93 .PP
94 To request the last Monday, etc.
95 in a month, ask for the \[lq]5th\[rq] one.
96 This will always match the last Monday, etc., even if there are
97 only four Mondays in the month:
98 .IP
99 .nf
100 \f[C]
101 #\ run\ at\ 11\ am\ on\ the\ first\ and\ last\ Mon,\ Tue,\ Wed\ of\ each\ month
102 0\ 11\ 1,5\ *\ mon-wed\ date
103 \f[]
106 When the fourth Monday in a month is the last, it will match
107 against both the \[lq]4th\[rq] and the \[lq]5th\[rq] (it will only
108 run once if both are specified).
110 The following formats are also recognized:
113 \f[C]
114 #\ schedule\ this\ job\ only\ once,\ when\ crond\ starts\ up
115 \@reboot\ date
117 #\ schedule\ this\ job\ whenever\ crond\ is\ running,\ and\ sees\ that\ at\ least\ one
118 #\ hour\ has\ elapsed\ since\ it\ last\ ran
119 \@hourly\ ID=job1\ date
120 \f[]
123 The formats \@hourly, \@daily, \@weekly, \@monthly, and \@yearly
124 need to update timestamp files when their jobs have been run.
125 The timestamp files are saved as
126 /var/spool/cron/cronstamps/user.jobname.
127 So for all of these formats, the cron command needs a jobname,
128 given by prefixing the command with \f[C]ID=jobname\f[].
129 (This syntax was chosen to maximize the chance that our crontab
130 files will be readable by other cron daemons as well.
131 They might just interpret the ID=jobname as a command-line
132 environment variable assignment.)
134 There's also this esoteric option, whose usefulness will be
135 explained later:
138 \f[C]
139 #\ don\[aq]t\ ever\ schedule\ this\ job\ on\ its\ own;\ only\ run\ it\ when\ it\[aq]s\ triggered
140 #\ as\ a\ "dependency"\ of\ another\ job\ (see\ below),\ or\ when\ the\ user\ explicitly
141 #\ requests\ it\ through\ the\ "cron.update"\ file\ (see\ crond(8))
142 \@noauto\ ID=namedjob\ date
143 \f[]
146 There's also a format available for finer-grained control of
147 frequencies:
150 \f[C]
151 #\ run\ whenever\ it\[aq]s\ between\ 2-4\ am,\ and\ at\ least\ one\ day\ (1d)
152 #\ has\ elapsed\ since\ this\ job\ ran
153 *\ 2-4\ *\ *\ *\ ID=job2\ FREQ=1d\ date
155 #\ as\ before,\ but\ re-try\ every\ 10\ minutes\ (10m)\ if\ my_command
156 #\ exits\ with\ code\ 11\ (EAGAIN)
157 *\ 2-4\ *\ *\ *\ ID=job3\ FREQ=1d/10m\ my_command
158 \f[]
161 These formats also update timestamp files, and so also require
162 their jobs to be assigned IDs.
164 Notice the technique used in the second example: jobs can exit with
165 code 11 to indicate they lacked the resources to run (for example,
166 no network was available), and so should be tried again after a
167 brief delay.
168 This works for jobs using either \@freq or FREQ=\&... formats; but
169 the FREQ=\&.../10m syntax is the only way to customize the length
170 of the delay before re-trying.
172 Jobs can be made to \[lq]depend\[rq] on, or wait until AFTER other
173 jobs have successfully completed.
174 Consider the following crontab:
177 \f[C]
178 *\ *\ *\ *\ *\ ID=job4\ FREQ=1d\ first_command
179 *\ *\ *\ *\ *\ ID=job5\ FREQ=1h\ AFTER=job4/30m\ second_command
180 \f[]
183 Here, whenever job5 is up to be run, if job4 is scheduled to run
184 within the next 30 minutes (30m), job5 will first wait for it to
185 successfully complete.
187 (What if job4 doesn't successfully complete? If job4 returns with
188 exit code EAGAIN, job5 will continue to wait until job4 is
189 retried\[em]even if that won't be within the hour.
190 If job4 returns with any other non-zero exit code, job5 will be
191 removed from the queue without running.)
193 Jobs can be told to wait for multiple other jobs, as follows:
196 \f[C]
197 10\ *\ *\ *\ *\ ID=job6\ AFTER=job4/1h,job7\ third_command
198 \f[]
201 The waiting job6 doesn't care what order job4 and job7 complete in.
202 If job6 comes up to be re-scheduled (an hour later) while an
203 earlier instance is still waiting, only a single instance of job6
204 will remain in the queue.
205 It will have all of its \[lq]waiting flags\[rq] reset: so each of
206 job7 and job4 (supposing again that job4 would run within the next
207 1h) will again have to complete before job6 will run.
209 If a job waits on a \@reboot or \@noauto job, the target job being
210 waited on will also be scheduled to run.
211 This technique can be used to have a common job scheduled as
212 \@noauto that several other jobs depend on (and so call as a
213 subroutine).
215 The command portion of a cron job is run with
216 \f[C]/bin/sh\ -c\ ...\f[] and may therefore contain any valid
217 Bourne shell command.
218 A common practice is to prefix your command with \f[B]exec\f[] to
219 keep the process table uncluttered.
220 It is also common to redirect job output to a file or to /dev/null.
221 If you do not, and the command generates output on stdout or
222 stderr, that output will be mailed to the local user whose crontab
223 the job comes from.
224 If you have crontabs for special users, such as uucp, who can't
225 receive local mail, you may want to create mail aliases for them or
226 adjust this behavior.
227 (See crond(8) for details how to adjust it.)
229 Whenever jobs return an exit code that's neither 0 nor 11 (EAGAIN),
230 that event will be logged, regardless of whether any stdout or
231 stderr is generated.
232 The job's timestamp will also be updated, and it won't be run again
233 until it would next be normally scheduled.
234 Any jobs waiting on the failed job will be canceled; they won't be
235 run until they're next scheduled.
236 .SH TODO
238 Ought to be able to have several crontab files for any given user,
239 as an organizational tool.
240 .SH SEE ALSO
242 \f[B]crond\f[](8)
243 .SH AUTHORS
245 Matthew Dillon (dillon\@apollo.backplane.com): original
246 developer
247 .PD 0
250 Jim Pryor (profjim\@jimpryor.net): current
251 developer