1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1989 AT&T
44 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
45 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved
46 .\" Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
47 .\"
48 .TH CRONTAB 1 "Aug 20, 2020"
49 .SH NAME
50 crontab \- user crontab file
51 .SH SYNOPSIS
52 .nf
53 \fB/usr/bin/crontab\fR [\fB-u\fR \fIusername\fR] [\fIfilename\fR]
54 .fi
55
56 .LP
57 .nf
58 \fB/usr/bin/crontab\fR \fB{ -e | -l | -r }\fR [\fIusername\fR]
59 .fi
60
61 .LP
62 .nf
63 \fB/usr/bin/crontab\fR \fB-u\fR \fIusername\fR \fB{ -e | -l | -r }\fR
64 .fi
65
66 .LP
67 .nf
68 \fB/usr/xpg4/bin/crontab\fR [\fIfilename\fR]
69 .fi
70
71 .LP
72 .nf
73 \fB/usr/xpg4/bin/crontab\fR \fB{ -e | -l | -r }\fR [\fIusername\fR]
74 .fi
75
76 .LP
77 .nf
78 \fB/usr/xpg4/bin/crontab\fR \fB-u\fR \fIusername\fR \fB{ -e | -l | -r }\fR
79 .fi
80
81 .LP
82 .nf
83 \fB/usr/xpg6/bin/crontab\fR [\fIfilename\fR]
84 .fi
85
86 .LP
87 .nf
88 \fB/usr/xpg6/bin/crontab\fR \fB{ -e | -l | -r }\fR [\fIusername\fR]
89 .fi
90
91 .LP
92 .nf
93 \fB/usr/xpg6/bin/crontab\fR \fB-u\fR \fIusername\fR \fB{ -e | -l | -r }\fR
94 .fi
95
96 .SH DESCRIPTION
97 The \fBcrontab\fR utility manages a user's access with \fBcron\fR (see
98 \fBcron\fR(1M)) by copying, creating, listing, and removing \fBcrontab\fR
99 files. If invoked without options, \fBcrontab\fR copies the specified file, or
100 the standard input if no file is specified, into a directory that holds all
101 users' crontabs.
102 .sp
103 .LP
104 If \fBcrontab\fR is invoked with \fIfilename\fR, this overwrites an existing
105 \fBcrontab\fR entry for the user that invokes it, or for the user specified
106 with the \fB-u\fR option.
107 .SS "\fBcrontab\fR Access Control"
108 Users: Access to \fBcrontab\fR is allowed:
109 .RS +4
110 .TP
111 .ie t \(bu
112 .el o
113 if the user's name appears in \fB/etc/cron.d/cron.allow\fR.
114 .RE
115 .RS +4
116 .TP
117 .ie t \(bu
118 .el o
119 if \fB/etc/cron.d/cron.allow\fR does not exist and the user's name is not in
120 \fB/etc/cron.d/cron.deny\fR.
121 .RE
122 .sp
123 .LP
124 Users: Access to \fBcrontab\fR is denied:
125 .RS +4
126 .TP
127 .ie t \(bu
128 .el o
129 if \fB/etc/cron.d/cron.allow\fR exists and the user's name is not in it.
130 .RE
131 .RS +4
132 .TP
133 .ie t \(bu
134 .el o
135 if \fB/etc/cron.d/cron.allow\fR does not exist and user's name is in
136 \fB/etc/cron.d/cron.deny\fR.
137 .RE
138 .RS +4
139 .TP
140 .ie t \(bu
141 .el o
142 if neither file exists, only a user with the \fBsolaris.jobs.user\fR
143 authorization is allowed to submit a job.
144 .RE
145 .RS +4
146 .TP
147 .ie t \(bu
148 .el o
149 if Auditing is enabled, the user's shell is not audited and the user is
150 not the \fBcrontab\fR owner. This can occur if the user logs in by way of a
151 program, such as some versions of \fBSSH\fR, which does not set audit
152 parameters.
153 .RE
154 .sp
155 .LP
156 The rules for \fBallow\fR and \fBdeny\fR apply to \fBroot\fR only if the
157 \fBallow\fR/\fBdeny\fR files exist.
158 .sp
159 .LP
160 The \fBallow\fR/\fBdeny\fR files consist of one user name per line.
161 .SS "\fBcrontab\fR Entry Format"
162 A \fBcrontab\fR file consists of lines of six fields each. The fields are
163 separated by spaces or tabs. The first five are integer patterns that specify
164 the following:
165 .sp
166 .in +2
167 .nf
168 minute (0\(mi59),
169 hour (0\(mi23),
170 day of the month (1\(mi31),
171 month of the year (1\(mi12),
172 day of the week (0\(mi6 with 0=Sunday).
173 .fi
174 .in -2
175 .sp
176
177 .sp
178 .LP
179 Each of these patterns can be either an asterisk (meaning all legal values) or
180 a list of elements separated by commas. An element is either a number or two
181 numbers separated by a hyphen (meaning an inclusive range).
182 .LP
183 A range or asterisk can optionally be followed by a step value as
184 \fI/<number>\fR. For example, \fI2\(mi59/3\fR can be used in the minutes field
185 to specify every three minutes starting at 2 past the hour, or \fI*/2\fR in
186 the hours field means every two hours.
187 .LP
188 Time specified here is interpreted in the currently active timezone. At the top
189 of the crontab file this is the timezone which is set system-wide in
190 /etc/default/init. A user can add a line such as:
191 .sp
192 .in +2
193 .nf
194 TZ=\fItimezone\fR
195 .fi
196 .in -2
197 .sp
198
199 .sp
200 .LP
201 \&...and all subsequent entries will be interpreted using that timezone, until
202 a new \fBTZ=\fR\fItimezone\fR line is encountered. The specification of days
203 can be made by two fields (day of the month and day of the week). Both are
204 adhered to if specified as a list of elements. See \fBEXAMPLES\fR.
205 .sp
206 .LP
207 The sixth field of a line in a \fBcrontab\fR file is a string that is executed
208 by the shell at the specified times. A percent character in this field (unless
209 escaped by \fB\e\fR\|) is translated to a \fINEWLINE\fR character.
210 .sp
211 .LP
212 Only the first line (up to a \fB`\|%\|'\fR or end of line) of the command field
213 is executed by the shell. Other lines are made available to the command as
214 standard input. Any blank line or line beginning with a \fB`\|#\|'\fR is a
215 comment and is ignored.
216 .sp
217 .LP
218 The shell is invoked from your $HOME directory. As with $TZ, both $SHELL and
219 $HOME can be set by having a line such as:
220 .sp
221 .in +2
222 .nf
223 SHELL=/usr/bin/\fIsomeshell\fR
224 .fi
225 .in -2
226 .sp
227
228 .sp
229 .LP
230 \&...or:
231 .sp
232 .in +2
233 .nf
234 HOME=\fIsomedirectory\fR
235 .fi
236 .in -2
237 .sp
238
239 .sp
240 .LP
241 \&...which will take precedence for all the remaining entries in the
242 \fBcrontab\fR or until there is another \fBHOME\fR or \fBSHELL\fR entry. It is
243 invoked with an \fBarg0\fR of the basename of the $SHELL that is currently in
244 effect. A user who wants to have his \fB\&.profile\fR or equivalent file
245 executed must explicitly do so in the \fBcrontab\fR file. \fBcron\fR supplies
246 a default environment for every shell, defining HOME, LOGNAME, SHELL, TZ, and
247 PATH. The default PATH for user \fBcron\fR jobs is \fB/usr/bin\fR; while root
248 \fBcron\fR jobs default to \fB/usr/sbin:/usr/bin\fR. The default PATH can be
249 set in \fB/etc/default/cron\fR (see \fBcron\fR(1M)). The TZ, HOME, and SHELL
250 environment variables are set to match those that are in effect in the
251 \fBcrontab\fR file at the time.
252 .sp
253 .LP
254 If you do not redirect the standard output and standard error of your commands,
255 any generated output or errors are mailed to you.
256 .SS "\fBcrontab\fR Environment Variables"
257 The following variables are supported:
258 .sp
259 .ne 2
260 .na
261 \fBHOME\fR
262 .ad
263 .sp .6
264 .RS 4n
265 Allows the user to choose and alternative directory for cron to change
266 directory to prior to running the command. For example:
267 .sp
268 .in +2
269 .nf
270 HOME=/var/tmp
271 .fi
272 .in -2
273 .sp
274
275 .RE
276
277 .sp
278 .ne 2
279 .na
280 \fBSHELL\fR
281 .ad
282 .sp .6
283 .RS 4n
284 The name of the shell to use to run subsequent commands. For example:
285 .sp
286 .in +2
287 .nf
288 SHELL=/usr/bin/ksh
289 .fi
290 .in -2
291 .sp
292
293 .RE
294
295 .sp
296 .ne 2
297 .na
298 \fBTZ\fR
299 .ad
300 .sp .6
301 .RS 4n
302 Allows the user to choose the timezone in which the \fBcron\fR entries are run.
303 This effects both the environment of the command that is run and the timing of
304 the entry. For example, to have your entries run using the timezone for
305 Iceland, use:
306 .sp
307 .in +2
308 .nf
309 TZ=Iceland
310 .fi
311 .in -2
312 .sp
313
314 .RE
315
316 .sp
317 .LP
318 Each of these variables affects all of the lines that follow it in the
319 \fBcrontab\fR file, until it is reset by a subsequent line resetting that
320 variable. Hence, it is possible to have multiple timezones supported within a
321 single \fBcrontab\fR file.
322 .sp
323 .LP
324 The lines that are not setting these environment variables are the same as
325 crontab entries that conform to the UNIX standard and are described elsewhere
326 in this man page.
327 .SS "Setting \fBcron\fR Jobs Across Timezones"
328 The default timezone of the \fBcron\fR daemon sets the system-wide timezone for
329 \fBcron\fR entries. This, in turn, is by set by default system-wide using
330 \fB/etc/default/init\fR.
331 .sp
332 .LP
333 If some form of \fBdaylight savings\fR or \fBsummer/winter time\fR is in
334 effect, then jobs scheduled during the switchover period could be executed
335 once, twice, or not at all.
336 .SH OPTIONS
337 The following options are supported:
338 .sp
339 .ne 2
340 .na
341 \fB-e\fR
342 .ad
343 .RS 6n
344 Edits a copy of the current user's \fBcrontab\fR file, or creates an empty file
345 to edit if \fBcrontab\fR does not exist. When editing is complete, the file is
346 installed as the user's \fBcrontab\fR file.
347 .sp
348 The environment variable \fBEDITOR\fR determines which editor is invoked with
349 the \fB-e\fR option. All \fBcrontab\fR jobs should be submitted using
350 \fBcrontab\fR. Do not add jobs by just editing the \fBcrontab\fR file, because
351 \fBcron\fR is not aware of changes made this way.
352 .sp
353 If all lines in the \fBcrontab\fR file are deleted, the old \fBcrontab\fR file
354 is restored. The correct way to delete all lines is to remove the \fBcrontab\fR
355 file using the \fB-r\fR option.
356 .sp
357 If \fIusername\fR is specified, the specified user's \fBcrontab\fR file is
358 edited, rather than the current user's \fBcrontab\fR file. This can only be
359 done by root or by a user with the \fBsolaris.jobs.admin\fR authorization.
360 .RE
361
362 .sp
363 .ne 2
364 .na
365 \fB-l\fR
366 .ad
367 .RS 6n
368 Lists the \fBcrontab\fR file for the invoking user. Only root or a user with
369 the \fBsolaris.jobs.admin\fR authorization can specify a username following the
370 \fB-l\fR option to list the \fBcrontab\fR file of the specified user.
371 .RE
372
373 .sp
374 .ne 2
375 .na
376 \fB-r\fR
377 .ad
378 .RS 6n
379 Removes a user's \fBcrontab\fR from the \fBcrontab\fR directory. Only root or a
380 user with the \fBsolaris.jobs.admin\fR authorization can specify a username
381 following the \fB-r\fR option to remove the \fBcrontab\fR file of the specified
382 user.
383 .RE
384
385 .sp
386 .ne 2
387 .na
388 \fB-u\fR \fIusername\fR
389 .ad
390 .RS 6n
391 Specifies the name of the user whose \fBcrontab\fR is to be replaced, viewed or
392 modified. This can only be done by root or by a user with the
393 \fBsolaris.jobs.admin\fR authorization.
394
395 .RE
396
397 .SH EXAMPLES
398 \fBExample 1 \fRCleaning up Core Files
399 .sp
400 .LP
401 This example cleans up \fBcore\fR files every weekday morning at 3:15 am:
402
403 .sp
404 .in +2
405 .nf
406 \fB15 3 * * 1-5 find $HOME\fR \fB-name\fR\fBcore 2>/dev/null | xargs rm\fR \fB-f\fR
407 .fi
408 .in -2
409 .sp
410
411 .LP
412 \fBExample 2 \fRMailing a Birthday Greeting
413 .sp
414 .LP
415 This example mails a birthday greeting:
416
417 .sp
418 .in +2
419 .nf
420 \fB0 12 14 2 * mailx john%Happy Birthday!%Time for lunch.\fR
421 .fi
422 .in -2
423 .sp
424
425 .LP
426 \fBExample 3 \fRSpecifying Days of the Month and Week
427 .sp
428 .LP
429 This example runs a command on the first and fifteenth of each month, as well
430 as on every Monday:
431
432 .sp
433 .in +2
434 .nf
435 \fB0 0 1,15 * 1\fR
436 .fi
437 .in -2
438 .sp
439
440 .sp
441 .LP
442 To specify days by only one field, the other field should be set to *. For
443 example:
444
445 .sp
446 .in +2
447 .nf
448 \fB0 0 * * 1\fR
449 .fi
450 .in -2
451 .sp
452
453 .sp
454 .LP
455 would run a command only on Mondays.
456
457 .LP
458 \fBExample 4 \fRUsing step values:
459 .sp
460 .LP
461 This example runs a job every hour during the night and every 3 hours during
462 working hours.
463
464 .sp
465 .in +2
466 .nf
467 \fB0 8-18/3,19-7 * * *\fR
468 .fi
469 .in -2
470 .sp
471
472 .LP
473 and to run a job every 2 minutes, use:
474
475 .sp
476 .in +2
477 .nf
478 \fB*/2 * * * *\fR
479 .fi
480 .in -2
481 .sp
482
483 .LP
484 \fBExample 5 \fRUsing Environment Variables
485 .sp
486 .LP
487 The following entries take advantage of \fBcrontab\fR support for certain
488 environment variables.
489
490 .sp
491 .in +2
492 .nf
493 TZ=GMT
494 HOME=/local/home/user
495 SHELL=/usr/bin/ksh
496 0 0 * * * echo $(date) > midnight.GMT
497 TZ=PST
498 0 0 * * * echo $(date) > midnight.PST
499 TZ=EST
500 HOME=/local/home/myuser
501 SHELL=/bin/csh
502 .fi
503 .in -2
504 .sp
505
506 .sp
507 .LP
508 The preceding entries allow two jobs to run. The first one would run at
509 midnight in the GMT timezone and the second would run at midnight in the PST
510 timezone. Both would be run in the directory \fB/local/home/user\fR using the
511 Korn shell. The file concludes with \fBTZ\fR, \fBHOME\fR, and \fBSHELL\fR
512 entries that return those variable to their default values.
513
514 .SH ENVIRONMENT VARIABLES
515 See \fBenviron\fR(5) for descriptions of the following environment variables
516 that affect the execution of \fBcrontab\fR: \fBLANG\fR, \fBLC_ALL\fR,
517 \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
518 .SS "\fB/usr/bin/crontab\fR"
519 .ne 2
520 .na
521 \fBEDITOR\fR
522 .ad
523 .RS 10n
524 Determine the editor to be invoked when the \fB-e\fR option is specified. This
525 is overridden by the \fBVISUAL\fR environmental variable. The default editor is
526 \fBvi\fR(1).
527 .RE
528
529 .sp
530 .ne 2
531 .na
532 \fBPATH\fR
533 .ad
534 .RS 10n
535 The \fBPATH\fR in \fBcrontab\fR's environment specifies the search path used to
536 find the editor.
537 .RE
538
539 .sp
540 .ne 2
541 .na
542 \fBVISUAL\fR
543 .ad
544 .RS 10n
545 Determine the visual editor to be invoked when the \fB-e\fR option is
546 specified. If \fBVISUAL\fR is not specified, then the environment variable
547 \fBEDITOR\fR is used. If that is not set, the default is \fBvi\fR(1).
548 .RE
549
550 .SS "\fB/usr/xpg4/bin/crontab\fR"
551 .ne 2
552 .na
553 \fBEDITOR\fR
554 .ad
555 .RS 10n
556 Determine the editor to be invoked when the \fB-e\fR option is specified. The
557 default editor is \fB/usr/xpg4/bin/vi\fR.
558 .RE
559
560 .SS "\fB/usr/xpg6/bin/crontab\fR"
561 .ne 2
562 .na
563 \fBEDITOR\fR
564 .ad
565 .RS 10n
566 Determine the editor to be invoked when the \fB-e\fR option is specified. The
567 default editor is \fB/usr/xpg6/bin/vi\fR.
568 .RE
569
570 .SH EXIT STATUS
571 The following exit values are returned:
572 .sp
573 .ne 2
574 .na
575 \fB0\fR
576 .ad
577 .RS 6n
578 Successful completion.
579 .RE
580
581 .sp
582 .ne 2
583 .na
584 \fB>0\fR
585 .ad
586 .RS 6n
587 An error occurred.
588 .RE
589
590 .SH FILES
591 .ne 2
592 .na
593 \fB/etc/cron.d\fR
594 .ad
595 .RS 28n
596 main cron directory
597 .RE
598
599 .sp
600 .ne 2
601 .na
602 \fB/etc/cron.d/cron.allow\fR
603 .ad
604 .RS 28n
605 list of allowed users
606 .RE
607
608 .sp
609 .ne 2
610 .na
611 \fB/etc/default/cron\fR
612 .ad
613 .RS 28n
614 contains cron default settings
615 .RE
616
617 .sp
618 .ne 2
619 .na
620 \fB/etc/cron.d/cron.deny\fR
621 .ad
622 .RS 28n
623 list of denied users
624 .RE
625
626 .sp
627 .ne 2
628 .na
629 \fB/var/cron/log\fR
630 .ad
631 .RS 28n
632 accounting information
633 .RE
634
635 .sp
636 .ne 2
637 .na
638 \fB/var/spool/cron/crontabs\fR
639 .ad
640 .RS 28n
641 spool area for \fBcrontab\fR
642 .RE
643
644 .SH ATTRIBUTES
645 See \fBattributes\fR(5) for descriptions of the following attributes:
646 .SS "\fB/usr/bin/crontab\fR"
647
648 .TS
649 box;
650 c | c
651 l | l .
652 ATTRIBUTE TYPE ATTRIBUTE VALUE
653 _
654 Interface Stability Standard
655 .TE
656
657 .SS "\fB/usr/xpg4/bin/crontab\fR"
658
659 .TS
660 box;
661 c | c
662 l | l .
663 ATTRIBUTE TYPE ATTRIBUTE VALUE
664 _
665 Interface Stability Standard
666 .TE
667
668 .SS "\fB/usr/xpg6/bin/crontab\fR"
669
670 .TS
671 box;
672 c | c
673 l | l .
674 ATTRIBUTE TYPE ATTRIBUTE VALUE
675 _
676 Interface Stability Standard
677 .TE
678
679 .SH SEE ALSO
680 \fBatq\fR(1), \fBatrm\fR(1), \fBauths\fR(1), \fBed\fR(1), \fBsh\fR(1),
681 \fBvi\fR(1), \fBcron\fR(1M), \fBsu\fR(1M), \fBauth_attr\fR(4),
682 \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5)
683 .SH NOTES
684 If you inadvertently enter the \fBcrontab\fR command with no arguments, do not
685 attempt to get out with Control-d. This removes all entries in your
686 \fBcrontab\fR file. Instead, exit with Control-c.
687 .sp
688 .LP
689 When updating \fBcron\fR, check first for existing \fBcrontab\fR entries that
690 can be scheduled close to the time of the update. Such entries can be lost if
691 the update process completes after the scheduled event. This can happen
692 because, when \fBcron\fR is notified by \fBcrontab\fR to update the internal
693 view of a user's \fBcrontab\fR file, it first removes the user's existing
694 internal \fBcrontab\fR and any internal scheduled events. Then it reads the new
695 \fBcrontab\fR file and rebuilds the internal \fBcrontab\fR and events. This
696 last step takes time, especially with a large \fBcrontab\fR file, and can
697 complete \fBafter\fR an existing \fBcrontab\fR entry is scheduled to run if it
698 is scheduled too close to the update. To be safe, start a new job at least 60
699 seconds after the current date and time.
700 .sp
701 .LP
702 If an authorized user other than root modifies another user's \fBcrontab\fR
703 file, the resulting behavior can be unpredictable. Instead, the authorized user
704 should first use \fBsu\fR(1M) to become superuser to the other user's login
705 before making any changes to the \fBcrontab\fR file.
706 .sp
707 .LP
708 Care should be taken when adding \fBTZ\fR, \fBSHELL\fR and \fBHOME\fR variables
709 to the \fBcrontab\fR file when the \fBcrontab\fR file could be shared with
710 applications that do not expect those variables to be changed from the default.
711 Resetting the values to their defaults at the bottom of the file will minimize
712 the risk of problems.