1.\"/* Copyright 1988,1990,1993,1994 by Paul Vixie 2.\" * All rights reserved 3.\" */ 4.\" 5.\"Copyright (c) 1997 by Internet Software Consortium 6.\" 7.\"Permission to use, copy, modify, and distribute this software for any 8.\"purpose with or without fee is hereby granted, provided that the above 9.\"copyright notice and this permission notice appear in all copies. 10.\" 11.\"THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS 12.\"ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 13.\"OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE 14.\"CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 15.\"DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 16.\"PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 17.\"ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 18.\"SOFTWARE. 19.\" 20.\" $Id: crontab.5,v 1.2 1998/08/14 00:32:38 vixie Exp $ 21.\" 22.Dd May 10, 2024 23.Dt CRONTAB 5 24.Os 25.Sh NAME 26.Nm crontab 27.Nd tables for driving cron 28.Sh DESCRIPTION 29A 30.Nm 31file contains instructions to the 32.Xr cron 8 33daemon of the general form: ``run this command at this time on this date''. 34Each user has their own crontab, and commands in any given crontab will be 35executed as the user who owns the crontab. 36Uucp and News will usually have 37their own crontabs, eliminating the need for explicitly running 38.Xr su 1 39as part of a cron command. 40.Pp 41Blank lines and leading spaces and tabs are ignored. 42Lines whose first 43non-space character is a pound-sign (#) are comments, and are ignored. 44Note that comments are not allowed on the same line as cron commands, since 45they will be taken to be part of the command. 46Similarly, comments are not 47allowed on the same line as environment variable settings. 48.Pp 49An active line in a crontab will be either an environment setting or a cron 50command. 51An environment setting is of the form, 52.Bd -literal 53 name = value 54.Ed 55.Pp 56where the spaces around the equal-sign (=) are optional, and any subsequent 57non-leading spaces in 58.Em value 59will be part of the value assigned to 60.Em name . 61The 62.Em value 63string may be placed in quotes (single or double, but matching) to preserve 64leading or trailing blanks. 65The 66.Em name 67string may also be placed in quote (single or double, but matching) 68to preserve leading, trailing or inner blanks. 69.Pp 70Several environment variables are set up 71automatically by the 72.Xr cron 8 73daemon. 74.Ev SHELL 75is set to 76.Pa /bin/sh , 77and 78.Ev LOGNAME 79and 80.Ev HOME 81are set from the 82.Pa /etc/passwd 83line of the crontab's owner. 84In addition, the environment variables of the 85user's login class will be set from 86.Pa /etc/login.conf.db 87and 88.Pa ~/.login_conf . 89(A setting of 90.Ev HOME 91in the login class will override the value from 92.Pa /etc/passwd , 93but will not change the current directory when the command is 94invoked, which can only be overridden with an explicit setting of 95.Ev HOME 96within the crontab file itself.) 97If 98.Ev PATH 99is not set by any other means, it is defaulted to 100.Pa /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin . 101.Ev HOME , 102.Ev PATH 103and 104.Ev SHELL , 105and any variables set from the login class, 106may be overridden by settings in the crontab; 107.Ev LOGNAME 108may not. 109.Pp 110(Another note: the 111.Ev LOGNAME 112variable is sometimes called 113.Ev USER 114on 115.Bx 116systems... 117On these systems, 118.Ev USER 119will be set also). 120.Pp 121If 122.Xr cron 8 123has any reason to send mail as a result of running commands in 124``this'' crontab, it will respect the following settings which may be 125defined in the crontab (but which are not taken from the login class). 126If 127.Ev MAILTO 128is defined (and non-empty), mail is 129sent to the user so named. 130If 131.Ev MAILCC 132is defined (and non-empty), mail is carbon copied to the user(s) so named. 133.Ev MAILBCC 134is defined (and non-empty), 135mail is blind carbon copied to the user(s) so named. 136If 137.Ev MAILFROM 138is defined (and non-empty), its value will be used as the from address. 139.Ev MAILTO 140, 141.Ev MAILCC 142and 143.Ev MAILBCC 144may also be used to direct mail to multiple recipients 145by separating recipient users with a comma. 146If 147.Ev MAILTO 148is defined but empty (MAILTO=""), no 149mail will be sent. 150Otherwise mail is sent to the owner of the crontab. 151This 152option is useful if you decide on 153.Pa /bin/mail 154instead of 155.Pa /usr/lib/sendmail 156as 157your mailer when you install cron -- 158.Pa /bin/mail 159does not do aliasing, and UUCP 160usually does not read its mail. 161.Pp 162The format of a cron command is very much the V7 standard, with a number of 163upward-compatible extensions. 164.Pp 165Each user cron line has five time and date fields, followed by a command. 166.Pp 167Each line in system crontab ( 168.Pa /etc/crontab, /etc/cron.d, /usr/local/etc/cron.d 169) has five time and date fields, followed by a valid user name 170(with optional ``:<group>'' and ``/<login-class>'' suffixes), 171followed by a command. 172.Pp 173Commands are executed by 174.Xr cron 8 175when the minute, hour, and month of year fields match the current time, 176.Em and 177when at least one of the two day fields (day of month, or day of week) 178matches the current time (see ``Note'' below). 179.Xr cron 8 180examines cron entries once every minute. 181The time and date fields are: 182.Bd -literal -offset indent 183field allowed values 184----- -------------- 185minute 0-59 186hour 0-23 187day of month 1-31 188month 1-12 (or names, see below) 189day of week 0-7 (0 or 7 is Sun, or use names) 190.Ed 191.Pp 192A field may be an asterisk (*), which always stands for ``first\-last''. 193.Pp 194Ranges of numbers are allowed. 195Ranges are two numbers separated 196with a hyphen. 197The specified range is inclusive. 198For example, 1998-11 for an ``hours'' entry specifies execution at hours 8, 9, 10 200and 11. 201.Pp 202Lists are allowed. 203A list is a set of numbers (or ranges) 204separated by commas. 205Examples: ``1,2,5,9'', ``0-4,8-12''. 206.Pp 207Step values can be used in conjunction with ranges. 208Following 209a range with ``/<number>'' specifies skips of the number's value 210through the range. 211For example, ``0-23/2'' can be used in the hours 212field to specify command execution every other hour (the alternative 213in the V7 standard is ``0,2,4,6,8,10,12,14,16,18,20,22''). 214Steps are 215also permitted after an asterisk, so if you want to say ``every two 216hours'', just use ``*/2''. 217.Pp 218Names can also be used for the ``month'' and ``day of week'' 219fields. 220Use the first three letters of the particular 221day or month (case does not matter). 222Ranges and lists are also allowed. 223.Pp 224The ``sixth'' field (the rest of the line) specifies the command to be 225run. 226One or more command options may precede the command to modify processing 227behavior. 228The entire command portion of the line, up to a newline or % 229character, will be executed by 230.Pa /bin/sh 231or by the shell 232specified in the 233.Ev SHELL 234variable of the cronfile. 235Percent-signs (%) in the command, unless escaped with backslash 236(\\), will be changed into newline characters, and all data 237after the first % will be sent to the command as standard 238input. 239.Pp 240The following command options can be supplied: 241.Bl -tag -width Ds 242.It Fl n 243No mail is sent after a successful run. 244The execution output will only be mailed if the command exits with a non-zero 245exit code. 246The 247.Fl n 248option is an attempt to cure potentially copious volumes of mail coming from 249.Xr cron 8 . 250.It Fl q 251Execution will not be logged. 252.El 253.sp 254Duplicate options are not allowed. 255.Pp 256Note: The day of a command's execution can be specified by two 257fields \(em day of month, and day of week. 258If both fields are 259restricted (ie, are not *), the command will be run when 260.Em either 261field matches the current time. 262For example, 263``30 4 1,15 * 5'' 264would cause a command to be run at 4:30 am on the 1st and 15th of each 265month, plus every Friday. 266.Pp 267Instead of the first five fields, 268a line may start with 269.Sq @ 270symbol followed either by one of eight special strings or by a numeric value. 271The recognized special strings are: 272.Bd -literal -offset indent 273string meaning 274------ ------- 275@reboot Run once, at startup of cron. 276@yearly Run once a year, "0 0 1 1 *". 277@annually (same as @yearly) 278@monthly Run once a month, "0 0 1 * *". 279@weekly Run once a week, "0 0 * * 0". 280@daily Run once a day, "0 0 * * *". 281@midnight (same as @daily) 282@hourly Run once an hour, "0 * * * *". 283@every_minute Run once a minute, "*/1 * * * *". 284@every_second Run once a second. 285.Ed 286.Pp 287The 288.Sq @ 289symbol followed by a numeric value has a special notion of running 290a job that many seconds after completion of the previous invocation of 291the job. 292Unlike regular syntax, it guarantees not to overlap two or more 293invocations of the same job during normal cron execution. 294Note, however, that overlap may occur if the job is running when the file 295containing the job is modified and subsequently reloaded. 296The first run is scheduled for the specified number of seconds after cron 297is started or the crontab entry is reloaded. 298.Sh EXAMPLE SYSTEM CRON FILE 299.Bd -literal 300# sample /etc/cron.d/vmstat 301# run vmstat every five minutes 302# note the username as sixth field! 303*/5 * * * * root vmstat 304.Ed 305.Sh EXAMPLE USER CRON FILE 306.Bd -literal 307# use /bin/sh to run commands, overriding the default set by cron 308SHELL=/bin/sh 309# mail any output to `paul', no matter whose crontab this is 310MAILTO=paul 311# CC and BCC mail to `lakshmikanth@example.com' and 'paul@example.com' 312MAILCC=lakshmikanth@example.com,paul@example.com 313MAILBCC=peter@example.com 314# run five minutes after midnight, every day 3155 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1 316# run at 2:15pm on the first of every month -- output mailed to paul 31715 14 1 * * $HOME/bin/monthly 318# run at 10 pm on weekdays, annoy Joe 3190 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?% 32023 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday" 3215 4 * * sun echo "run at 5 after 4 every sunday" 322# run at 5 minutes intervals, no matter how long it takes 323@300 svnlite up /usr/src 324# run every minute, suppress logging 325* * * * * -q date 326# run every minute, only send mail if ping fails 327* * * * * -n ping -c 1 freebsd.org 328.Ed 329.Sh SEE ALSO 330.Xr crontab 1 , 331.Xr cron 8 332.Sh EXTENSIONS 333When specifying day of week, both day 0 and day 7 will be considered Sunday. 334.Bx 335and 336.Tn ATT 337seem to disagree about this. 338.Pp 339Lists and ranges are allowed to co-exist in the same field. 340"1-3,7-9" would 341be rejected by 342.Tn ATT 343or 344.Bx 345cron -- they want to see "1-3" or "7,8,9" ONLY. 346.Pp 347Ranges can include "steps", so "1-9/2" is the same as "1,3,5,7,9". 348.Pp 349Names of months or days of the week can be specified by name. 350.Pp 351Environment variables can be set in the crontab. 352In 353.Bx 354or 355.Tn ATT , 356the 357environment handed to child processes is basically the one from 358.Pa /etc/rc . 359.Pp 360Command output is mailed to the crontab owner 361.No ( Bx 362cannot do this), can be 363mailed to a person other than the crontab owner (SysV cannot do this), or the 364feature can be turned off and no mail will be sent at all (SysV cannot do this 365either). 366.Pp 367All of the 368.Sq @ 369directives that can appear in place of the first five fields 370are extensions. 371.Pp 372Command processing can be modified using command options. 373The 374.Sq -q 375option suppresses logging. 376The 377.Sq -n 378option does not mail on successful run. 379.Sh AUTHORS 380.An Paul Vixie Aq Mt paul@vix.com 381.Sh BUGS 382If you are in one of the 70-odd countries that observe Daylight 383Savings Time, jobs scheduled during the rollback or advance may be 384affected if 385.Xr cron 8 386is not started with the 387.Fl s 388flag. 389In general, it is not a good idea to schedule jobs during 390this period if 391.Xr cron 8 392is not started with the 393.Fl s 394flag, which is enabled by default. 395See 396.Xr cron 8 397for more details. 398.Pp 399For US timezones (except parts of AZ and HI) the time shift occurs at 4002AM local time. 401For others, the output of the 402.Xr zdump 8 403program's verbose 404.Fl ( v ) 405option can be used to determine the moment of time shift. 406