1crontab(1) User Commands crontab(1)
2
3
4
6 crontab - user crontab file
7
9 /usr/bin/crontab [filename]
10
11
12 /usr/bin/crontab -e [username]
13
14
15 /usr/bin/crontab -l [username]
16
17
18 /usr/bin/crontab -r [username]
19
20
21 /usr/xpg4/bin/crontab [filename]
22
23
24 /usr/xpg4/bin/crontab -e [username]
25
26
27 /usr/xpg4/bin/crontab -l [username]
28
29
30 /usr/xpg4/bin/crontab -r [username]
31
32
33 /usr/xpg6/bin/crontab [filename]
34
35
36 /usr/xpg6/bin/crontab -e [username]
37
38
39 /usr/xpg6/bin/crontab -l [username]
40
41
42 /usr/xpg6/bin/crontab -r [username]
43
44
46 The crontab utility manages a user's access with cron (see cron(1M)) by
47 copying, creating, listing, and removing crontab files. If invoked
48 without options, crontab copies the specified file, or the standard
49 input if no file is specified, into a directory that holds all users'
50 crontabs.
51
52
53 If crontab is invoked with filename, this overwrites an existing
54 crontab entry for the user that invokes it.
55
56 crontab Access Control
57 Users: Access to crontab is allowed:
58
59 o if the user's name appears in /etc/cron.d/cron.allow.
60
61 o if /etc/cron.d/cron.allow does not exist and the user's name
62 is not in /etc/cron.d/cron.deny.
63
64
65 Users: Access to crontab is denied:
66
67 o if /etc/cron.d/cron.allow exists and the user's name is not
68 in it.
69
70 o if /etc/cron.d/cron.allow does not exist and user's name is
71 in /etc/cron.d/cron.deny.
72
73 o if neither file exists, only a user with the
74 solaris.jobs.user authorization is allowed to submit a job.
75
76 o if Solaris Auditing is enabled, the user's shell is not
77 audited and the user is not the crontab owner. This can
78 occur if the user logs in by way of a program, such as some
79 versions of SSH, which does not set audit parameters.
80
81
82 The rules for allow and deny apply to root only if the allow/deny files
83 exist.
84
85
86 The allow/deny files consist of one user name per line.
87
88 crontab Entry Format
89 A crontab file consists of lines of six fields each. The fields are
90 separated by spaces or tabs. The first five are integer patterns that
91 specify the following:
92
93 minute (0−59),
94 hour (0−23),
95 day of the month (1−31),
96 month of the year (1−12),
97 day of the week (0−6 with 0=Sunday).
98
99
100
101
102 Each of these patterns can be either an asterisk (meaning all legal
103 values) or a list of elements separated by commas. An element is either
104 a number or two numbers separated by a minus sign (meaning an inclusive
105 range). Time specified here is interpreted in the currently active
106 timezone. At the top of the crontab file this is the timezone which is
107 set system-wide in /etc/default/init. A user can add a line such as:
108
109 TZ=timezone
110
111
112
113
114 ...and all subsequent entries will be interpreted using that timezone,
115 until a new TZ=timezone line is encountered. The specification of days
116 can be made by two fields (day of the month and day of the week). Both
117 are adhered to if specified as a list of elements. See EXAMPLES.
118
119
120 The sixth field of a line in a crontab file is a string that is exe‐
121 cuted by the shell at the specified times. A percent character in this
122 field (unless escaped by \) is translated to a NEWLINE character.
123
124
125 Only the first line (up to a `%' or end of line) of the command field
126 is executed by the shell. Other lines are made available to the command
127 as standard input. Any blank line or line beginning with a `#' is a
128 comment and is ignored.
129
130
131 The shell is invoked from your $HOME directory. As with $TZ, both
132 $SHELL and $HOME can be set by having a line such as:
133
134 SHELL=/usr/bin/someshell
135
136
137
138
139 ...or:
140
141 HOME=somedirectory
142
143
144
145
146 ...which will take precedence for all the remaining entries in the
147 crontab or until there is another HOME or SHELL entry. It is invoked
148 with an arg0 of the basename of the $SHELL that is currently in effect.
149 A user who wants to have his .profile or equivalent file executed must
150 explicitly do so in the crontab file. cron supplies a default environ‐
151 ment for every shell, defining HOME, LOGNAME, SHELL, TZ, and PATH. The
152 default PATH for user cron jobs is /usr/bin; while root cron jobs
153 default to /usr/sbin:/usr/bin. The default PATH can be set in
154 /etc/default/cron (see cron(1M)). The TZ, HOME, and SHELL environment
155 variables are set to match those that are in effect in the crontab file
156 at the time.
157
158
159 If you do not redirect the standard output and standard error of your
160 commands, any generated output or errors are mailed to you.
161
162 crontab Environment Variables
163 The following variables are supported:
164
165 HOME
166
167 Allows the user to choose and alternative directory for cron to
168 change directory to prior to running the command. For example:
169
170 HOME=/var/tmp
171
172
173
174
175 SHELL
176
177 The name of the shell to use to run subsequent commands. For exam‐
178 ple:
179
180 SHELL=/usr/bin/ksh
181
182
183
184
185 TZ
186
187 Allows the user to choose the timezone in which the cron entries
188 are run. This effects both the environment of the command that is
189 run and the timing of the entry. For example, to have your entries
190 run using the timezone for Iceland, use:
191
192 TZ=Iceland
193
194
195
196
197
198 Each of these variables affects all of the lines that follow it in the
199 crontab file, until it is reset by a subsequent line resetting that
200 variable. Hence, it is possible to have multiple timezones supported
201 within a single crontab file.
202
203
204 The lines that are not setting these environment variables are the
205 same as crontab entries that conform to the UNIX standard and are
206 described elsewhere in this man page.
207
208 Setting cron Jobs Across Timezones
209 The default timezone of the cron daemon sets the system-wide timezone
210 for cron entries. This, in turn, is by set by default system-wide using
211 /etc/default/init.
212
213
214 If some form of daylight savings or summer/winter time is in effect,
215 then jobs scheduled during the switchover period could be executed
216 once, twice, or not at all.
217
219 The following options are supported:
220
221 -e Edits a copy of the current user's crontab file, or creates an
222 empty file to edit if crontab does not exist. When editing is
223 complete, the file is installed as the user's crontab file.
224
225 The environment variable EDITOR determines which editor is
226 invoked with the -e option. All crontab jobs should be submitted
227 using crontab. Do not add jobs by just editing the crontab file,
228 because cron is not aware of changes made this way.
229
230 If all lines in the crontab file are deleted, the old crontab
231 file is restored. The correct way to delete all lines is to
232 remove the crontab file using the -r option.
233
234 If username is specified, the specified user's crontab file is
235 edited, rather than the current user's crontab file. This can
236 only be done by root or by a user with the solaris.jobs.admin
237 authorization.
238
239
240 -l Lists the crontab file for the invoking user. Only root or a user
241 with the solaris.jobs.admin authorization can specify a username
242 following the -l option to list the crontab file of the specified
243 user.
244
245
246 -r Removes a user's crontab from the crontab directory. Only root or
247 a user with the solaris.jobs.admin authorization can specify a
248 username following the -r option to remove the crontab file of
249 the specified user.
250
251
253 Example 1 Cleaning up Core Files
254
255
256 This example cleans up core files every weekday morning at 3:15 am:
257
258
259 15 3 * * 1-5 find $HOME -namecore 2>/dev/null | xargs rm -f
260
261
262
263 Example 2 Mailing a Birthday Greeting
264
265
266 This example mails a birthday greeting:
267
268
269 0 12 14 2 * mailx john%Happy Birthday!%Time for lunch.
270
271
272
273 Example 3 Specifying Days of the Month and Week
274
275
276 This example runs a command on the first and fifteenth of each month,
277 as well as on every Monday:
278
279
280 0 0 1,15 * 1
281
282
283
284
285 To specify days by only one field, the other field should be set to *.
286 For example:
287
288
289 0 0 * * 1
290
291
292
293
294 would run a command only on Mondays.
295
296
297 Example 4 Using Environment Variables
298
299
300 The following entries take advantage of crontab support for certain
301 environment variables.
302
303
304 TZ=GMT
305 HOME=/local/home/user
306 SHELL=/usr/bin/ksh
307 0 0 * * * echo $(date) > midnight.GMT
308 TZ=PST
309 0 0 * * * echo $(date) > midnight.PST
310 TZ=EST
311 HOME=/local/home/myuser
312 SHELL=/bin/csh
313
314
315
316
317 The preceding entries allow two jobs to run. The first one would run at
318 midnight in the GMT timezone and the second would run at midnight in
319 the PST timezone. Both would be run in the directory /local/home/user
320 using the Korn shell. The file concludes with TZ, HOME, and SHELL
321 entries that return those variable to their default values.
322
323
325 See environ(5) for descriptions of the following environment variables
326 that affect the execution of crontab: LANG, LC_ALL, LC_CTYPE, LC_MES‐
327 SAGES, and NLSPATH.
328
329 /usr/bin/crontab
330 EDITOR Determine the editor to be invoked when the -e option is
331 specified. This is overridden by the VISUAL environmental
332 variable. The default editor is vi(1).
333
334
335 PATH The PATH in crontab's environment specifies the search path
336 used to find the editor.
337
338
339 VISUAL Determine the visual editor to be invoked when the -e option
340 is specified. If VISUAL is not specified, then the environ‐
341 ment variable EDITOR is used. If that is not set, the default
342 is vi(1).
343
344
345 /usr/xpg4/bin/crontab
346 EDITOR Determine the editor to be invoked when the -e option is
347 specified. The default editor is /usr/xpg4/bin/vi.
348
349
350 /usr/xpg6/bin/crontab
351 EDITOR Determine the editor to be invoked when the -e option is
352 specified. The default editor is /usr/xpg6/bin/vi.
353
354
356 The following exit values are returned:
357
358 0 Successful completion.
359
360
361 >0 An error occurred.
362
363
365 /etc/cron.d main cron directory
366
367
368 /etc/cron.d/cron.allow list of allowed users
369
370
371 /etc/default/cron contains cron default settings
372
373
374 /etc/cron.d/cron.deny list of denied users
375
376
377 /var/cron/log accounting information
378
379
380 /var/spool/cron/crontabs spool area for crontab
381
382
384 See attributes(5) for descriptions of the following attributes:
385
386 /usr/bin/crontab
387 ┌─────────────────────────────┬─────────────────────────────┐
388 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
389 ├─────────────────────────────┼─────────────────────────────┤
390 │Availability │SUNWcsu │
391 ├─────────────────────────────┼─────────────────────────────┤
392 │Interface Stability │Standard │
393 └─────────────────────────────┴─────────────────────────────┘
394
395 /usr/xpg4/bin/crontab
396 ┌─────────────────────────────┬─────────────────────────────┐
397 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
398 ├─────────────────────────────┼─────────────────────────────┤
399 │Availability │SUNWxcu4 │
400 ├─────────────────────────────┼─────────────────────────────┤
401 │Interface Stability │Standard │
402 └─────────────────────────────┴─────────────────────────────┘
403
404 /usr/xpg6/bin/crontab
405 ┌─────────────────────────────┬─────────────────────────────┐
406 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
407 ├─────────────────────────────┼─────────────────────────────┤
408 │Availability │SUNWxcu6 │
409 ├─────────────────────────────┼─────────────────────────────┤
410 │Interface Stability │Standard │
411 └─────────────────────────────┴─────────────────────────────┘
412
414 atq(1), atrm(1), auths(1), ed(1), sh(1), vi(1), cron(1M), su(1M),
415 auth_attr(4), attributes(5), environ(5), standards(5)
416
418 If you inadvertently enter the crontab command with no arguments, do
419 not attempt to get out with Control-d. This removes all entries in your
420 crontab file. Instead, exit with Control-c.
421
422
423 When updating cron, check first for existing crontab entries that can
424 be scheduled close to the time of the update. Such entries can be lost
425 if the update process completes after the scheduled event. This can
426 happen because, when cron is notified by crontab to update the internal
427 view of a user's crontab file, it first removes the user's existing
428 internal crontab and any internal scheduled events. Then it reads the
429 new crontab file and rebuilds the internal crontab and events. This
430 last step takes time, especially with a large crontab file, and can
431 complete after an existing crontab entry is scheduled to run if it is
432 scheduled too close to the update. To be safe, start a new job at least
433 60 seconds after the current date and time.
434
435
436 If an authorized user other than root modifies another user's crontab
437 file, the resulting behavior can be unpredictable. Instead, the autho‐
438 rized user should first use su(1M) to become superuser to the other
439 user's login before making any changes to the crontab file.
440
441
442 Care should be taken when adding TZ, SHELL and HOME variables to the
443 crontab file when the crontab file could be shared with applications
444 that do not expect those variables to be changed from the default.
445 Resetting the values to their defaults at the bottom of the file will
446 minimize the risk of problems.
447
448
449
450SunOS 5.11 6 Apr 2009 crontab(1)