1.\"/* Copyright 1988,1990,1993,1994 by Paul Vixie 2.\" * All rights reserved 3.\" */ 4.\" 5.\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 6.\" Copyright (c) 1997,2000 by Internet Software Consortium, Inc. 7.\" 8.\" Permission to use, copy, modify, and distribute this software for any 9.\" purpose with or without fee is hereby granted, provided that the above 10.\" copyright notice and this permission notice appear in all copies. 11.\" 12.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 13.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 15.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 18.\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19.\" 20.\" $OpenBSD: crontab.5,v 1.43 2024/07/06 15:33:17 jmc Exp $ 21.\" 22.Dd $Mdocdate: July 6 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: 34.Dq at these times on these dates run this command . 35There may be a system 36.Nm 37and each user may have their own 38.Nm . 39Commands in any given 40.Nm 41will be 42executed either as the user who owns the 43.Nm 44or, in the case of the system 45.Nm crontab , 46as the user specified on the command line. 47.Pp 48While a 49.Nm 50is a text file, it is not intended to be directly edited. 51Creation, modification, and removal of a 52.Nm 53should be done using 54.Xr crontab 1 . 55.Pp 56Blank lines, leading spaces, and tabs are ignored. 57Lines whose first non-space character is a pound sign 58.Pq Ql # 59are comments, and are ignored. 60Note that comments are not allowed on the same line as 61.Xr cron 8 62commands, since 63they will be taken to be part of the command. 64Similarly, comments are not 65allowed on the same line as environment variable settings. 66.Pp 67An active line in a 68.Nm 69is either an environment variable setting or a 70.Xr cron 8 71command. 72.Pp 73Environment variable settings create the environment 74any command in the 75.Nm 76is run in. 77An environment variable setting is of the form: 78.Pp 79.Dl name = value 80.Pp 81The spaces around the equal sign 82.Pq Ql = 83are optional, and any subsequent non-leading spaces in 84.Ar value 85will be part of the value assigned to 86.Ar name . 87The 88.Ar value 89string may be placed in quotes 90.Pq single or double , but matching 91to preserve leading or trailing blanks. 92.Pp 93Lines in the system 94.Nm 95have six fixed fields, an optional flags field, and a command, in the form: 96.Bd -ragged -offset indent 97.Ar minute 98.Ar hour 99.Ar day-of-month 100.Ar month 101.Ar day-of-week 102.Ar user 103.Op Ar flags 104.Ar command 105.Ed 106.Pp 107While lines in a user 108.Nm 109have five fixed fields, an optional flags field, and a command, in the form: 110.Bd -ragged -offset indent 111.Ar minute 112.Ar hour 113.Ar day-of-month 114.Ar month 115.Ar day-of-week 116.Op Ar flags 117.Ar command 118.Ed 119.Pp 120Fields are separated by blanks or tabs. 121The command may be one or more fields long. 122The allowed values for the fields are: 123.Bl -column "day-of-month" "allowed values" -offset indent 124.It Sy field Ta Sy allowed values 125.It Ar minute Ta *, ~, or 0\(en59 126.It Ar hour Ta *, ~, or 0\(en23 127.It Ar day-of-month Ta *, ~, or 1\(en31 128.It Ar month Ta *, ~, 1\(en12, or a name (see below) 129.It Ar day-of-week Ta *, ~, 0\(en7, or a name (0 or 7 is Sunday) 130.It Ar user Ta a valid username 131.It Op Ar flags Ta runtime flags, denoted with '-' 132.It Ar command Ta text 133.El 134.Pp 135Lists are allowed. 136A list is a set of numbers (or ranges) separated by commas. 137For example, 138.Dq 1,2,5,9 139or 140.Dq 0\(en4,8\(en12 . 141.Pp 142Ranges of numbers are allowed. 143Ranges are two numbers separated with a hyphen. 144The specified range is inclusive. 145For example, 1468\(en11 for an 147.Ar hour 148entry specifies execution at hours 8, 9, 10 and 11. 149.Pp 150A random value for a field may be obtained using the 151.Ql ~ 152character. 153A value is generated every time the tab is loaded. 154On its own, 155it denotes a random value appropriate for the field. 156It can also be used in a range to make the interval more specific. 157If either of the numbers in a range are omitted, 158the appropriate limit (low or high) for that field will be used. 159For example, both 160.Dq 0~30 161and 162.Dq ~30 163in the 164.Ar minute 165field would result in a random value between 0 and 30. 166.Pp 167Step values can be used in conjunction with ranges. 168Following a range with 169.No / Ns Ar number 170specifies skips of 171.Ar number 172through the range. 173For example, 174.Dq 0\(en23/2 175can be used in the 176.Ar hour 177field to specify command execution every other hour. 178Steps are also permitted after an asterisk, so to say 179.Dq every two hours , 180just use 181.Dq */2 . 182A step value after a random range will execute the command at a random 183offset less than the step size. 184For example, to avoid a thundering herd at the top and bottom of the hour, 185.Dq 0~59/30 186.Po 187or simply 188.Dq ~/30 189.Pc 190can be used in the 191.Ar minute 192field to specify that command execution happen twice an hour at 193consistent intervals. 194.Pp 195An asterisk 196.Pq Ql * 197is short form for a range of all allowed values. 198.Pp 199Names can be used in the 200.Ar month 201and 202.Ar day-of-week 203fields. 204Use the first three letters of the particular 205day or month (case doesn't matter). 206Ranges or lists of names are not allowed. 207.Pp 208Some 209.Ar flags 210relating to process operation can be provided before the 211.Ar command 212field. 213Flags are denoted with '-' and may be combined. 214.Bl -tag -width Ds 215.It Fl n Ar command 216No mail is sent after a successful run. 217The execution output will only be mailed if the command exits with a non-zero 218exit code. 219The 220.Fl n 221option is an attempt to cure potentially copious volumes of mail coming from 222.Xr cron 8 . 223.It Fl q Ar command 224Execution will not be logged. 225.It Fl s Ar command 226Only a single instance of 227.Ar command 228will be run concurrently. 229Additional instances of 230.Ar command 231will not be scheduled until the earlier one completes. 232.El 233.Pp 234The 235.Ar command 236field (the rest of the line) is the command to be 237run. 238The entire command portion of the line, up to a newline or % 239character, will be executed by 240.Pa /bin/sh 241or by the shell 242specified in the 243.Ev SHELL 244variable of the 245.Nm crontab . 246Percent signs 247.Pq Ql % 248in the command, unless escaped with a backslash 249.Pq Ql \e , 250will be changed into newline characters, and all data 251after the first 252.Ql % 253will be sent to the command as standard input. 254.Pp 255Commands are executed by 256.Xr cron 8 257when the 258.Ar minute , 259.Ar hour , 260and 261.Ar month 262fields match the current time, 263.Em and 264when at least one of the two day fields 265.Po Ar day-of-month 266or 267.Ar day-of-week Pc , 268match the current time. 269.Pp 270Note: The day of a command's execution can be specified by two 271fields \(em 272.Ar day-of-month 273and 274.Ar day-of-week . 275If both fields are restricted (i.e. aren't *), 276the command will be run when 277.Em either 278field matches the current time. 279For example, 280.Pp 281.Dl 30 4 1,15 * 5 282.Pp 283would cause a command to be run at 4:30 am on the 1st and 15th of each 284month, plus every Friday. 285.Pp 286Instead of the first five fields, one of eight special strings may appear: 287.Bl -column "@midnight" "meaning" -offset indent 288.It Sy string Ta Sy meaning 289.It @reboot Ta Run once, at startup. 290.It @yearly Ta Run every January 1 (0 0 1 1 *). 291.It @annually Ta The same as @yearly. 292.It @monthly Ta Run the first day of every month (0 0 1 * *). 293.It @weekly Ta Run every Sunday (0 0 * * 0). 294.It @daily Ta Run every midnight (0 0 * * *). 295.It @midnight Ta The same as @daily. 296.It @hourly Ta Run every hour, on the hour (0 * * * *). 297.El 298.Sh ENVIRONMENT 299.Bl -tag -width "LOGNAMEXXX" 300.It Ev HOME 301Set from the user's 302.Pa /etc/passwd 303entry. 304May be overridden by settings in the 305.Nm . 306.It Ev LOGNAME 307Set from the user's 308.Pa /etc/passwd 309entry. 310May not be overridden by settings in the 311.Nm . 312.It Ev MAILTO 313If 314.Ev MAILTO 315is defined and non-empty, 316mail is sent to the user so named. 317If 318.Ev MAILTO 319is defined but empty 320.Pq Ev MAILTO = Qq , 321no mail will be sent. 322Otherwise mail is sent to the owner of the 323.Nm . 324This is useful for pseudo-users that lack an alias 325that would otherwise redirect the mail to a real person. 326.It Ev SHELL 327Set to 328.Pa /bin/sh . 329May be overridden by settings in the 330.Nm . 331.It Ev USER 332Set from the user's 333.Pa /etc/passwd 334entry. 335May not be overridden by settings in the 336.Nm . 337.El 338.Sh FILES 339.Bl -tag -width "/var/cron/tabs/<user>XXX" -compact 340.It Pa /etc/crontab 341System crontab. 342.It Pa /var/cron/tabs/ Ns Aq Ar user 343User crontab. 344.El 345.Sh EXAMPLES 346.Bd -literal 347# use /bin/sh to run commands, no matter what /etc/passwd says 348SHELL=/bin/sh 349# mail any output to `paul', no matter whose crontab this is 350MAILTO=paul 351# 352# run five minutes after midnight, every day 3535 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1 354 355# run at 2:15pm on the first of every month -- job output will be sent 356# to paul, but only if $HOME/bin/monthly exits with a non-zero exit code 35715 14 1 * * -n $HOME/bin/monthly 358 359# run at 10 pm on weekdays, annoy Joe 3600 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?% 361 36223 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday" 363 3645 4 * * sun echo "run at 5 after 4 every sunday" 365 366# run hourly at a random time within the first 30 minutes of the hour 3670~30 * * * * /usr/libexec/spamd-setup 368.Ed 369.Sh SEE ALSO 370.Xr crontab 1 , 371.Xr cron 8 372.Sh STANDARDS 373The 374.Nm 375file format is compliant with the 376.St -p1003.1-2008 377specification. 378The behaviours described below are all extensions to that standard: 379.Bl -dash 380.It 381The 382.Ar day-of-week 383field may use 7 to represent Sunday. 384.It 385Ranges may include 386.Dq steps . 387.It 388Random intervals are supported using the 389.Ql ~ 390character. 391.It 392Months or days of the week can be specified by name. 393.It 394Environment variables can be set in a crontab. 395.It 396Command output can be mailed to a person other than the crontab 397owner, or the feature can be turned off and no mail will be sent 398at all. 399.It 400All of the 401.Ql @ 402commands that can appear in place of the first five fields. 403.It 404All of the 405.Op Fl nqs 406flags. 407.El 408.Sh AUTHORS 409.Nm 410was written by 411.An Paul Vixie Aq Mt vixie@isc.org . 412