1.\"/* Copyright 1988,1990,1993,1994 by Paul Vixie 2.\" * All rights reserved 3.\" */ 4.\" 5.\" Permission to use, copy, modify, and distribute this software for any 6.\" purpose with or without fee is hereby granted, provided that the above 7.\" copyright notice and this permission notice appear in all copies. 8.\" 9.\" THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS 10.\" ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 11.\" OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE 12.\" CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13.\" DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14.\" PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 15.\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 16.\" SOFTWARE. 17.\" 18.\" $OpenBSD: crontab.5,v 1.14 2001/08/02 18:37:34 mpech Exp $ 19.\" 20.Dd June 8, 1999 21.Dt CRONTAB 5 22.Os 23.Sh NAME 24.Nm crontab 25.Nd tables for driving cron 26.Sh DESCRIPTION 27A 28.Nm 29file contains instructions to the 30.Xr cron 8 31daemon of the general form: 32.Do 33at these times on these dates run this command 34.Dc . 35There may be a system 36.Nm 37.Pf ( Pa /etc/crontab ) 38and each user may have their own 39.Nm 40.Pf ( Pa /var/cron/tabs/<user> ) . 41Commands in any given 42.Nm 43will be 44executed either as the user who owns the 45.Nm 46or, in the case of the system 47.Nm crontab , 48as the user specified in the command line. 49Uucp and News will usually each have 50their own 51.Nm crontab , 52eliminating the need for explicitly running 53.Xr su 1 54as part of a 55.Xr cron 8 56command. 57.Pp 58While a 59.Nm 60is a text file, it is not intended to be directly edited. 61Creation, modification, and removal of a 62.Nm 63should be done using 64.Xr crontab 1 . 65.Pp 66Blank lines, leading spaces, and tabs are ignored. 67Lines whose first non-space character is a pound sign 68.Pq Ql # 69are comments, and are ignored. 70Note that comments are not allowed on the same line as 71.Xr cron 8 72commands, since 73they will be taken to be part of the command. 74Similarly, comments are not 75allowed on the same line as environment variable settings. 76.Pp 77An active line in a 78.Nm 79is either an environment variable setting or a 80.Xr cron 8 81command. 82.Pp 83.Em Environment Variable Settings 84.Pp 85Environment variable settings create the environment 86any command in the 87.Nm 88is run in. 89An environment variable setting is of the form: 90.Pp 91.Dl name \&= value 92.Pp 93where the spaces around the equal-sign 94.Pq Ql = 95are optional, and any subsequent non-leading spaces in 96.Fa value 97will be part of the value assigned to 98.Fa name . 99The 100.Fa value 101string may be placed in quotes 102.Pq single or double , but matching 103to preserve leading or trailing blanks. 104.Pp 105Several environment variables are set automatically by the 106.Xr cron 8 107daemon. 108.Ev SHELL 109is set to 110.Pa /bin/sh , 111and 112.Ev LOGNAME 113and 114.Ev HOME 115are set from the 116.Pa /etc/passwd 117line of the 118.Nm crontab Ns \&'s 119owner. 120.Ev HOME 121and 122.Ev SHELL 123may be overridden by settings in the 124.Nm crontab ; 125.Ev LOGNAME 126may not. 127.Pp 128Note: on BSD systems the 129.Ev LOGNAME 130variable is sometimes called 131.Ev USER . 132On 133.Ox , 134.Xr cron 8 135will set both 136.Ev USER 137and 138.Ev LOGNAME 139to the same value. 140.Pp 141In addition to 142.Ev LOGNAME , 143.Ev HOME , 144and 145.Ev SHELL , 146.Xr cron 8 147will look at 148.Ev MAILTO 149if it has any reason to send mail as a result of running 150commands in 151.Dq this 152.Nm crontab . 153If 154.Ev MAILTO 155is defined (and non-empty), 156mail is sent to the user so named. 157If 158.Ev MAILTO 159is defined but empty 160.Pq Ev MAILTO \&= Sq , 161no 162mail will be sent. 163Otherwise mail is sent to the owner of the 164.Nm crontab . 165This option is useful for pseudo-users that lack an alias 166that would otherwise redirect the mail to a real person. 167.Pp 168.Em cron Commands 169.Pp 170The format of a 171.Xr cron 8 172command is very much the V7 standard, with a number of 173upward-compatible extensions. 174Lines in the system 175.Nm 176have six fields in the form: 177.Bd -ragged -offset indent 178.Ar minute 179.Ar hour 180.Ar day\-of\-month 181.Ar month 182.Ar day\-of\-week 183.Ar user 184.Ar command 185.Ed 186.Pp 187while lines in a user 188.Nm 189have five fields in the form: 190.Bd -ragged -offset indent 191.Ar minute 192.Ar hour 193.Ar day\-of\-month 194.Ar month 195.Ar day\-of\-week 196.Ar command 197.Ed 198.Pp 199Fields are separated by blanks or tabs. 200The allowed values for the fields are: 201.Pp 202.Bl -tag -width "day-of-month" -compact -offset indent 203.It field 204allowed values 205.It ----- 206-------------- 207.It Ar minute 208* or 0\-59 209.It Ar hour 210* or 0\-23 211.It Ar day\&-of\&-month 212* or 1-31 213.It Ar month 214* or 1-12 or a name (see below) 215.It Ar day\&-of\&-week 216* or 0-7 or a name (0 or 7 is Sunday) 217.It Ar user 218a valid username 219.It Ar command 220text 221.El 222.Pp 223Lists are allowed. 224A list is a set of numbers (or ranges) separated by commas. 225Examples: 226.Sm off 227.Dq 1 , 2 , 5 , 9 , 228.Dq 0\&-4 , 8\&-12 . 229.Sm on 230.Pp 231Ranges of numbers are allowed. 232Ranges are two numbers separated with a hyphen. 233The specified range is inclusive. 234For example, 2358\-11 for an 236.Fa hour 237entry specifies execution at hours 8, 9, 10 and 11. 238.Pp 239Step values can be used in conjunction with ranges. 240Following a range with 241.No \&/ Ns Ar number 242specifies skips of 243.Fa number 244through the range. 245For example, 246.Dq 0-23/2 247can be used in the 248.Fa hour 249field to specify command execution every other hour (the alternative 250in the V7 standard is 251.Dq 0,2,4,6,8,10,12,14,16,18,20,22 ) . 252Steps are also permitted after an asterisk, so if you want to say 253.Dq every two hours , 254just use 255.Dq \&*\&/2 . 256.Pp 257An asterisk 258.Pq Ql * 259is short form for a range of all allowed values. 260.Pp 261Names can be used in the 262.Fa month 263and 264.Fa day\&-of\&-week 265fields. 266Use the first three letters of the particular 267day or month (case doesn't matter). 268Ranges or lists of names are not allowed. 269.Pp 270The 271.Fa command 272field (the rest of the line) is the command to be 273run. 274The entire command portion of the line, up to a newline or % 275character, will be executed by 276.Pa /bin/sh 277or by the shell 278specified in the 279.Ev SHELL 280variable of the 281.Nm crontab . 282Percent signs 283.Pq Ql % 284in the command, unless escaped with a backslash 285.Pq Ql \e , 286will be changed into newline characters, and all data 287after the first 288.Ql % 289will be sent to the command as standard input. 290.Pp 291Commands are executed by 292.Xr cron 8 293when the 294.Fa minute , 295.Fa hour , 296and 297.Fa month 298fields match the current time, 299.Em and 300when at least one of the two day fields 301.Pf ( Fa day\&-of\&-month 302or 303.Fa day\&-of\&-week , 304see Note below) match the current time. 305.Xr cron 8 306examines 307.Nm 308entries once every minute. 309.Pp 310Note: The day of a command's execution can be specified by two 311fields \(em 312.Ar day\&-of\&-month 313and 314.Ar day\&-of\&-week . 315If both fields are 316restricted (i.e., aren't *), the command will be run when 317.Em either 318field matches the current time. 319For example, 320.Pp 321.Dl 30 4 1\&,15 \&* 5 322.Pp 323would cause a command to be run at 4:30 am on the 1st and 15th of each 324month, plus every Friday. 325.Pp 326Instead of the first five fields, one of eight special strings may appear: 327.Pp 328.Bl -tag -width "@annually" -offset indent -compact 329.It string 330meaning 331.It ------ 332------- 333.It @reboot 334Run once, at 335.Xr cron 8 336startup. 337.It @yearly 338Run every January 1, "0 0 1 1 *". 339.It @annually 340(same as @yearly). 341.It @monthly 342Run the first day of every month, "0 0 1 * *". 343.It @weekly 344Run every Sunday, "0 0 * * 0". 345.It @daily 346Run every midnight, "0 0 * * *". 347.It @midnight 348(same as @daily). 349.It @hourly 350Run every hour, on the hour, "0 * * * *". 351.El 352.Sh EXAMPLES 353.Bd -literal 354# use /bin/sh to run commands, no matter what /etc/passwd says 355SHELL=/bin/sh 356# mail any output to `paul', no matter whose crontab this is 357MAILTO=paul 358# 359# run five minutes after midnight, every day 3605 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1 361# run at 2:15pm on the first of every month -- output mailed to paul 36215 14 1 * * $HOME/bin/monthly 363# run at 10 pm on weekdays, annoy Joe 3640 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?% 36523 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday" 3665 4 * * sun echo "run at 5 after 4 every sunday" 367.Ed 368.Sh SEE ALSO 369.Xr crontab 1 , 370.Xr cron 8 371.Sh EXTENSIONS 372When specifying 373.Fa day\&-of\&-week , 374both day 0 and day 7 will be considered Sunday. 375BSD and ATT seem to disagree about this. 376.Pp 377Lists and ranges are allowed to coexist in the same field. 378.Dq 1\&-3,7\&-9 379would 380be rejected by ATT or BSD 381.Xr cron 382\(em they want to see 383.Dq 1\&-3 384or 385.Dq 7,8,9 386.Em only . 387.Pp 388Ranges can include 389.Dq steps , 390so 391.Dq 1-9/2 392is the same as 393.Dq 1,3,5,7,9 . 394.Pp 395Months or days of the week can be specified by name. 396.Pp 397Environment variables can be set in the crontab. 398In BSD or ATT, the 399environment handed to child processes is basically the one from /etc/rc. 400.Pp 401Command output is mailed to the crontab owner (BSD can't do this), can be 402mailed to a person other than the crontab owner (SysV can't do this), or the 403feature can be turned off and no mail will be sent at all (SysV can't do this 404either). 405.Pp 406All of the 407.Ql @ 408commands that can appear in place of the first five fields 409are extensions. 410.Sh AUTHORS 411Paul Vixie <paul@vix.com> 412