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