Index: usr.sbin/cron/cron/cron.8 =================================================================== --- usr.sbin/cron/cron/cron.8 +++ usr.sbin/cron/cron/cron.8 @@ -49,17 +49,16 @@ utility searches .Pa /var/cron/tabs for crontab files which are named after accounts in -.Pa /etc/passwd ; -crontabs found are loaded into memory. +.Pa /etc/passwd . The .Nm -utility also searches for -.Pa /etc/crontab -and files in -.Pa /etc/cron.d +utility also searches for system crontab files in +.Pa /etc/crontab , +.Pa /etc/cron.d , and -.Pa /usr/local/etc/cron.d -which are in a different format (see +.Pa /usr/local/etc/cron.d . +Any crontabs found are loaded into memory. +System crontab files are in a different format (see .Xr crontab 5 ) . .Pp The @@ -73,9 +72,8 @@ .Xr pam 3 and skips the command if the account is unavailable, e.g., locked out or expired. -Commands from -.Pa /etc/crontab -bypass this check. +Commands from system crontabs bypass this check. +.Pp When executing commands, any output is mailed to the owner of the crontab (or to the user named in the @@ -88,8 +86,7 @@ Additionally, .Nm checks each minute to see if its spool directory's modification time (or -the modification time on -.Pa /etc/crontab ) +the modification time on any system crontab files) has changed, and if it has, .Nm will then examine the modification time on all crontabs and reload those @@ -121,10 +118,14 @@ moments when a lot of jobs are likely to start at once, e.g., at the beginning of the first minute of each hour. .It Fl J Ar rootjitter -Enable time jitter for superuser jobs. +Enable time jitter for superuser (uid=0) jobs. The same as .Fl j except that it will affect jobs run by the superuser only. +These jobs are either in the superuser's system crontab, +or a system crontab when the +.Em who +field is specified as a superuser. .It Fl m Ar mailto Overrides the default recipient for .Nm @@ -224,9 +225,9 @@ configuration file for .Nm .It Pa /usr/local/etc/cron.d -Directory for third-party package provided crontab files. +Directory for third-party package provided system crontab files. .It Pa /var/cron/tabs -Directory for personal crontab files +Directory for user crontab files .El .Sh SEE ALSO .Xr crontab 1 , Index: usr.sbin/cron/crontab/crontab.5 =================================================================== --- usr.sbin/cron/crontab/crontab.5 +++ usr.sbin/cron/crontab/crontab.5 @@ -30,24 +30,40 @@ .Nm file contains instructions to the .Xr cron 8 -daemon of the general form: ``run this command at this time on this date''. -Each user has their own crontab, and commands in any given crontab will be -executed as the user who owns the crontab. -Uucp and News will usually have -their own crontabs, eliminating the need for explicitly running +daemon of the general form: ``run this command at this time on this day''. +Each user (including any superusers) can have their own crontab. +Commands in any given crontab will be executed as the user who owns +the crontab. +Accounts for services (such as Uucp or News) can have their own crontab, +eliminating the need for explicitly running .Xr su 1 as part of a cron command. .Pp +.Fx also has a system crontab format, for +.Pa /etc/crontab , +.Pa /etc/cron.d , +or +.Pa /usr/local/etc/cron.d +files. +The system crontab has an additional field +.Pq Em who +to specify the user, group, or login class to run the command as +.Po see +.Sx SYSTEM CRONTAB +.Pc . +.Pp +An active line in a crontab will be either an environment setting or +a cron command. +.Ss WHITESPACE AND COMMENTS Blank lines and leading spaces and tabs are ignored. +.Pp Lines whose first non-space character is a pound-sign (#) are comments, and are ignored. -Note that comments are not allowed on the same line as cron commands, since +Comments are not allowed on the same line as cron commands, since they will be taken to be part of the command. Similarly, comments are not allowed on the same line as environment variable settings. -.Pp -An active line in a crontab will be either an environment setting or a cron -command. +.Ss ENVIRONMENT SETTING An environment setting is of the form, .Bd -literal name = value @@ -64,7 +80,7 @@ leading or trailing blanks. The .Em name -string may also be placed in quote (single or double, but matching) +string may also be placed in quotes (single or double, but matching) to preserve leading, trailing or inner blanks. .Pp Several environment variables are set up @@ -148,27 +164,31 @@ .Pa /bin/mail does not do aliasing, and UUCP usually does not read its mail. -.Pp +.Ss CRON COMMAND The format of a cron command is very much the V7 standard, with a number of upward-compatible extensions. .Pp -Each user cron line has five time and date fields, followed by a command. -.Pp -Each line in system crontab ( -.Pa /etc/crontab, /etc/cron.d, /usr/local/etc/cron.d -) has five time and date fields, followed by a valid user name -(with optional ``:'' and ``/'' suffixes), -followed by a command. +Each user cron line has five time and day fields, followed by a command. .Pp Commands are executed by .Xr cron 8 when the minute, hour, and month of year fields match the current time, .Em and when at least one of the two day fields (day of month, or day of week) -matches the current time (see ``Note'' below). +matches the current time +.Po see +.Sx TIME AND DAY FIELDS +.Pc . .Xr cron 8 examines cron entries once every minute. -The time and date fields are: +.Pp +If time jitter is enabled, +.Xr cron 8 +will sleep a random number of seconds in the range from 0 to +.Ar jitter +prior to executing commands. +.Ss TIME AND DAY FIELDS +The time and day fields are: .Bd -literal -offset indent field allowed values ----- -------------- @@ -176,7 +196,7 @@ hour 0-23 day of month 1-31 month 1-12 (or names, see below) -day of week 0-7 (0 or 7 is Sun, or use names) +day of week 0-7 (0 or 7 is Sun, or use names) .Ed .Pp A field may be an asterisk (*), which always stands for ``first\-last''. @@ -285,6 +305,66 @@ containing the job is modified and subsequently reloaded. The first run is scheduled for the specified number of seconds after cron is started or the crontab entry is reloaded. +.Ss COMMAND OPTIONS +The following command options can be supplied: +.Bl -tag -width Ds +.It Fl n +Do not send mail after a successful run. +The execution output will only be mailed if the command exits with +a non-zero exit code. +The +.Fl n +option is an attempt to cure potentially copious volumes of mail coming from +.Xr cron 8 . +.It Fl q +Execution will not be logged. +.El +.sp +Duplicate options are not allowed. +.Ss SYSTEM CRONTAB +The system crontab format is the same as the user crontab format with +the addition of a field (who) between the time and day fields and the command. +This required field is used to specify the user to run the command as. +.Pp +To specify the group to run as, append a colon ``:'' followed by the +group name. +The group must have an entry in +.Pa /etc/group , +see +.Xr group 5 . +The group is optional. +.Pp +To specify the login class to run as, append a forward-slash ``/'' +followed by the login class. The login class must have an entry in +the login capabilities database, see +.Xr login.conf 5 . +The login class is optional. +If not specified, the login class will be ``daemon''. +.Pp +If both the group and login class are specified, +the group must precede the login class. +.Pp +The system cron command fields are: +.Bd -literal -offset indent +field allowed values +----- -------------- +minute 0-59 +hour 0-23 +day of month 1-31 +month 1-12 (or names) +day of week 0-7 (or names) +who username[:group][/loginclass] +command [command options] command +.Ed +.Pp +All fields other than +.Em who +function the same as in a user cron command. +.Pp +If an invalid group or login class is specified, +.Xr cron 8 +will stop processing the crontab, +and no further commands will be loaded from that crontab. .Sh EXAMPLE SYSTEM CRON FILE .Bd -literal # sample /etc/cron.d/vmstat