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.41 2020/04/18 17:11:40 jmc Exp $ 21.\" 22.Dd $Mdocdate: April 18 2020 $ 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 * or 1\(en12 or a name (see below) 129.It Ar day-of-week Ta * or 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 (within the legal range) may be obtained by using the 151.Ql ~ 152character in a field. 153The interval of the random value may be specified explicitly, for example 154.Dq 0~30 155will result in a random value between 0 and 30 inclusive. 156If either (or both) of the numbers on either side of the 157.Ql ~ 158are omitted, the appropriate limit (low or high) for the field will be used. 159.Pp 160Step values can be used in conjunction with ranges (but not random ranges 161which represent a single number). 162Following a range with 163.No / Ns Ar number 164specifies skips of 165.Ar number 166through the range. 167For example, 168.Dq 0\(en23/2 169can be used in the 170.Ar hour 171field to specify command execution every other hour. 172Steps are also permitted after an asterisk, so to say 173.Dq every two hours , 174just use 175.Dq */2 . 176.Pp 177An asterisk 178.Pq Ql * 179is short form for a range of all allowed values. 180.Pp 181Names can be used in the 182.Ar month 183and 184.Ar day-of-week 185fields. 186Use the first three letters of the particular 187day or month (case doesn't matter). 188Ranges or lists of names are not allowed. 189.Pp 190Some 191.Ar flags 192relating to process operation can be provided before the 193.Ar command 194field. 195Flags are denoted with '-' and may be combined. 196.Bl -tag -width Ds 197.It Fl n Ar command 198No mail is sent after a successful run. 199The execution output will only be mailed if the command exits with a non-zero 200exit code. 201The 202.Fl n 203option is an attempt to cure potentially copious volumes of mail coming from 204.Xr cron 8 . 205.It Fl q Ar command 206Execution will not be logged. 207.It Fl s Ar command 208Only a single instance of 209.Ar command 210will be run concurrently. 211Additional instances of 212.Ar command 213will not be scheduled until the earlier one completes. 214.El 215.Pp 216The 217.Ar command 218field (the rest of the line) is the command to be 219run. 220The entire command portion of the line, up to a newline or % 221character, will be executed by 222.Pa /bin/sh 223or by the shell 224specified in the 225.Ev SHELL 226variable of the 227.Nm crontab . 228Percent signs 229.Pq Ql % 230in the command, unless escaped with a backslash 231.Pq Ql \e , 232will be changed into newline characters, and all data 233after the first 234.Ql % 235will be sent to the command as standard input. 236.Pp 237Commands are executed by 238.Xr cron 8 239when the 240.Ar minute , 241.Ar hour , 242and 243.Ar month 244fields match the current time, 245.Em and 246when at least one of the two day fields 247.Po Ar day-of-month 248or 249.Ar day-of-week Pc , 250match the current time. 251.Pp 252Note: The day of a command's execution can be specified by two 253fields \(em 254.Ar day-of-month 255and 256.Ar day-of-week . 257If both fields are restricted (i.e. aren't *), 258the command will be run when 259.Em either 260field matches the current time. 261For example, 262.Pp 263.Dl 30 4 1,15 * 5 264.Pp 265would cause a command to be run at 4:30 am on the 1st and 15th of each 266month, plus every Friday. 267.Pp 268Instead of the first five fields, one of eight special strings may appear: 269.Bl -column "@midnight" "meaning" -offset indent 270.It Sy string Ta Sy meaning 271.It @reboot Ta Run once, at startup. 272.It @yearly Ta Run every January 1 (0 0 1 1 *). 273.It @annually Ta The same as @yearly. 274.It @monthly Ta Run the first day of every month (0 0 1 * *). 275.It @weekly Ta Run every Sunday (0 0 * * 0). 276.It @daily Ta Run every midnight (0 0 * * *). 277.It @midnight Ta The same as @daily. 278.It @hourly Ta Run every hour, on the hour (0 * * * *). 279.El 280.Sh ENVIRONMENT 281.Bl -tag -width "LOGNAMEXXX" 282.It Ev HOME 283Set from the user's 284.Pa /etc/passwd 285entry. 286May be overridden by settings in the 287.Nm . 288.It Ev LOGNAME 289Set from the user's 290.Pa /etc/passwd 291entry. 292May not be overridden by settings in the 293.Nm . 294.It Ev MAILTO 295If 296.Ev MAILTO 297is defined and non-empty, 298mail is sent to the user so named. 299If 300.Ev MAILTO 301is defined but empty 302.Pq Ev MAILTO = Qq , 303no mail will be sent. 304Otherwise mail is sent to the owner of the 305.Nm . 306This is useful for pseudo-users that lack an alias 307that would otherwise redirect the mail to a real person. 308.It Ev SHELL 309Set to 310.Pa /bin/sh . 311May be overridden by settings in the 312.Nm . 313.It Ev USER 314Set from the user's 315.Pa /etc/passwd 316entry. 317May not be overridden by settings in the 318.Nm . 319.El 320.Sh FILES 321.Bl -tag -width "/var/cron/tabs/<user>XXX" -compact 322.It Pa /etc/crontab 323System crontab. 324.It Pa /var/cron/tabs/ Ns Aq Ar user 325User crontab. 326.El 327.Sh EXAMPLES 328.Bd -literal 329# use /bin/sh to run commands, no matter what /etc/passwd says 330SHELL=/bin/sh 331# mail any output to `paul', no matter whose crontab this is 332MAILTO=paul 333# 334# run five minutes after midnight, every day 3355 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1 336 337# run at 2:15pm on the first of every month -- job output will be sent 338# to paul, but only if $HOME/bin/monthly exits with a non-zero exit code 33915 14 1 * * -n $HOME/bin/monthly 340 341# run at 10 pm on weekdays, annoy Joe 3420 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?% 343 34423 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday" 345 3465 4 * * sun echo "run at 5 after 4 every sunday" 347 348# run hourly at a random time within the first 30 minutes of the hour 3490~30 * * * * /usr/libexec/spamd-setup 350.Ed 351.Sh SEE ALSO 352.Xr crontab 1 , 353.Xr cron 8 354.Sh STANDARDS 355The 356.Nm 357file format is compliant with the 358.St -p1003.1-2008 359specification. 360The behaviours described below are all extensions to that standard: 361.Bl -dash 362.It 363The 364.Ar day-of-week 365field may use 7 to represent Sunday. 366.It 367Ranges may include 368.Dq steps . 369.It 370Random intervals are supported using the 371.Ql ~ 372character. 373.It 374Months or days of the week can be specified by name. 375.It 376Environment variables can be set in a crontab. 377.It 378Command output can be mailed to a person other than the crontab 379owner, or the feature can be turned off and no mail will be sent 380at all. 381.It 382All of the 383.Ql @ 384commands that can appear in place of the first five fields. 385.It 386All of the 387.Op Fl nqs 388flags. 389.El 390.Sh AUTHORS 391.Nm 392was written by 393.An Paul Vixie Aq Mt vixie@isc.org . 394