Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Un archivo crontab le dice al Cron daemon qué comandos ejecutar y cuándo ejecutarlos. Tiene tres tipos diferentes de líneas: comando cron (cron command), configuracion del entorno (environment setting), y comentario (comment). Se ignoran las líneas en blanco, los espacios iniciales y las tabulaciones.

Comentarios

Any line whose first non-whitespace character is a pound-sign (#) will be considered a comment. Inline comments are not allowed. Comments are not processed by the Cron daemon.

Environment Setting

Cualquier línea cuyo primer carácter que no sea un espacio en blanco, sea un signo de almohadilla (#) se considerará un comentario. No se permiten comentarios en línea. Los comentarios no son procesados ​​por el Cron daemon.

Configuración del Entorno

La configuración del entorno esta en forma deEnvironment setting is in the form of:

Code Block
languagetext
name = value

Whitespace around the equal sign (=) are optional, and everything to the right of the equal sign is considered part of the value. The value can be quoted (with single or double quotes) to preserve leading or trailing spaces. Many environment variables are assigned a default value:

Los espacios en blanco alrededor del signo igual (=) son opcionales y todo lo que se encuentra a la derecha del signo igual se considera parte del valor. El valor se puede citar (con comillas simples o dobles) para conservar los espacios iniciales o finales. A muchas variables de entorno se les asigna un valor predeterminado:

  • SHELL se establece en SHELL is set to /bin/sh.
  • HOME and LOGNAME are set by  LOGNAME se establece en /etc/passwd.

SHELL and HOME can be overridden by environment settings, but LOGNAME can not.The MAILTO variable is checked to see if mail needs to be sent. By default, mail is sent to the owner of the crontab. Mail can be sent to another email address by assigning it to MAILTO. If you don't want Cron to send mail, assign MAILTO to the empty string HOME puede ser anulado por la configuración del entorno, pero no puede con LOGNAME.

La variable MAILTO se comprueba para ver si es necesario enviar el correo. de forma predeterminada, el correo se envía al propietario del crontab. El correo se puede enviar a otra dirección de correo electrónico asignándolo a MAILTO. Si no desea que Cron envíe correo, signe MAILTO. Si no desea que Cron envíe correo, asigne MAILTO a la cadena vacía (MAILTO=""). The MAILTO variable will only affect where emails are sent for commands that come after the line it is assigned. If you want to change all the email address of all commands, you would need to assign MAILTO at the top of the file. If you want to change the email address for a single command, you would set MAILTO directly above the command, and then set MAILTO back to its previous value before the next command.

Cron Commands

A cron command has six fields: five date and time fields, and a command field. The Cron daemon checks the schedule of each job every minute. A job is run whenever the time, and date matches the current time and date.

La variable MAILTO solo afectará a dónde se envían los correos electrónicos para los comandos que vienen después de la línea asignada. Si desea cambiar todas las direcciones de correo electrónico de todos los comandos, deberá asignar MAILTO en la parte superior del archivo. Si desea cambiar la dirección de correo electrónico para un solo comando, configuraría MAILTO directamente sobre el comando y luego restablecería MAILTO a su valor anterior antes del siguiente comando.

Cron Commands

Un comando cron tiene seis campos: cinco campos de fecha y hora, y un campo de comando. El Cron daemon verifica la programación de cada trabajo cada minuto. Un trabajo se ejecuta siempre que la hora y la fecha coincidan con la hora y la fecha actuales.

Un comando cron completo se verá asíA full cron command will look something like this:

Code Block
languagetext
0 0 * * * /path/to/command

Scheduling

The five date and time fields are minutehourday of the monthmonth, and day of the week respectivelyLos cinco campos de fecha y hora son minutoshorasdia del mesmes, y dia de la semana respectivamente:

Code Block
languagetext
┌───────────── minute
│ ┌───────────── hour
│ │ ┌───────────── day of the month
│ │ │ ┌───────────── month
│ │ │ │ ┌───────────── day of the week
│ │ │ │ │
│ │ │ │ │
│ │ │ │ │
* * * * *

Above diagram courtesy of Diagrama de arriba cortesía de Wikipedia.

FieldFilaAccepted ValuesValores aceptados
minuteminuto0-59
hourhora0-23
day of the monthdía del mes1-31
monthmes1-12 or names (see below)
day of the weekdía de la semana0-7 (Sunday is 0 or 7) or names

Los Cron jobs are run whenever the  minute se ejecutan siempre que los campos de minuto  hour , and  month  fields match the current time, and when  at least one of  the  day of the month , or  day of the year  fields matches.Names for days of the week, or months are the first three letters of a day or month (e.g Mon for Monday, Oct for October).

Note

Crons scheduled to run at times that can be "skipped" may result in jobs not running when you expect them to. A cron scheduled to run on the 31st of each month would only run during January, March, May, July, August, October, and November. If a daylight savings time change occurs, a cron job scheduled to run at a time that is skipped, or occurs twice will be skipped or be executed twice respectively.

All fields may contain an asterisk (*) which stands for any value.

Ranges are allowed, and are written as two numbers separated by a hyphen (-). Ranges are inclusive.

hora , y  mes coincidan con la hora actual, y cuando al menos uno de los campos de día del mes, o  día del año  los nombres de los dias de la semana o los meses son los primeros tres letras de un dia o mes (por ejemplo, Mon para lunes, Oct para Octubre).

Note

Los cron programados para ejecutarse en momentos que se pueden "omitir" pueden provocar que los trabajos no se ejecuten cuando se espera que lo hagan. Un cron programado para ejecutarse el 31 de cada mes solo se ejecutará durante enero, marzo, mayo, julio, agosto, octubre y noviembre. Si se produce un cambio de horario de verano, un trabajo cron programado para ejecutarse a una hora que se omite, o se produce dos veces, se omitirá o se ejecutará dos veces, respectivamente.

Todos los campos pueden contener un asterisco (*) que representa cualquier valor.

Los rangos están permitidos y se escriben como dos números separados por un guión (-). Los rangos son inclusivos.

Las listas están permitidas y son números o rangos separados por comas, p. Lists are allowed, and are numbers or ranges separated by commas e.g.  1,3,5,7 , or o 0-7,16-23.

Step values may be used with ranges. A step value is written as a range followed by a forward slash (/), and a number. The number will tell the Cron daemon how many times it should skip that job before running it again. The value 0-23/2 in the hour field tells Cron to execute the command every other hour. Step values may be used with asterisks as well so */2 will also tell Cron to run a command every other hour.

Commands

The last field of a cron command is the command to be run. Specifically, everything after the day of the week field until a newline or '%' character is considered to be part of the command, and will be executed by the shell set in the SHELL environment variable (/bin/sh by default).

All '%' characters in a command are converted to newline characters. A literal '%' must be escaped with a preceding backslash (\) e.g. \%. No other characters need to be escaped in a command.

Extensions

Los valores de paso se pueden usar con rangos. Un valor de paso se escribe como un rango seguido de una barra inclinada (/) y un número. El número le dirá al demonio Cron cuántas veces debe omitir ese trabajo antes de volver a ejecutarlo. El valor 0-23/2 en el campo de la hora le dice a Cron que ejecute el comando cada dos horas. Los valores de paso también se pueden usar con asteriscos, por lo que */2 también le indicará a Cron que ejecute un comando cada dos horas.


Comandos

El último campo de un comando cron es el comando que se ejecutará. Específicamente, todo lo que esté después del campo dia de la semana hasta una nueva línea o un carácter '%' se considera parte del comando, y será ejecutado por el shell establecido en la variable de entorno SHELL (/bin/sh por defecto).

Todos los caracteres '%' en un comando se convierten en caracteres de nueva línea. Un '%' literal debe ir acompañado de una barra invertida (\), por ejemplo \%. No es necesario escapar de otros caracteres en un comando.

Extensiones

Hay varias abreviaturas de tiempo especiales que se pueden usar en lugar de los cinco campos de fecha y horaThere are a handful of special time shorthand that may be used instead of the five date and time fields.

ShorthandValue
@rebootRuns once after a reboot.Ejecutar después de reinicio
@yearly or @annuallyRun once a year Ejecutar una vez al año (0 0 1 1 *).
@monthlyRun once a month Ejecutar una vez al mes (0 0 1 * *).
@weeklyRun once a week Ejecutar una vez a la semana (0 0 * * 0).
@dailyRun once a day Ejecutar una vez al dia (0 0 * * *).
@hourlyRun once an hour Ejecutar cada hora (0 * * * *).

Examples

Ejemplos

Un comando que se ejecuta cada minutoA command that runs every minute:

Code Block
languagetext
* * * * * /path/to/command

A command that runs every 5th minute on the hour (e.gUn comando que se ejecuta cada minuto 5 (ejemplo. 1:05, 2:05, 3:05 etc.):

Code Block
languagetext
5 * * * * /path/to/command

A command that runs every 10 minutesUn comando que se ejecuta cada 10 minutos:

Code Block
languagetext
titleRange
0,10,20,30,40,50 * * * * /path/to/command

Un comando que se ejecute cada 6 minutos

Code Block
languagetext
titleStep
*/6 * * * * /path/to/command

A command that runs every Monday at Un comando que se ejecuta todos los lunes a las 8:00 AM:

Code Block
languagetext
0 8 * * 1 /path/to/command

A command that runs the first Tuesday of every month at Un comando que se ejecuta el primer martes de cada mes a las 5:30 PMp. m.:

Code Block
languagetext
30 17 1-7 * 2 /path/to/command

...