condiciones OR crontables

condiciones OR crontables

Los parámetros crontables parecen funcionar como condiciones "y". Entonces el ejemplo

0 9-5 * * 1-5

Se ejecuta cuando se cumplen las condiciones "el minuto es cero Y la hora es entre 9 y 5 Y el día es entre lunes y viernes".

Lo que me gustaría es una función 'o', para poder decir "ejecutar de lunes a viernes O el octavo día del mes". ¿Existe tal cosa?

Me doy cuenta de que podrías agregar dos entradas, pero con muchas entradas agrega algo para olvidar.

Respuesta1

Iba a decir: use ,(coma). De man 5 crontab:

Lists are allowed.
A list is a set of numbers  (or  ranges)  separated  by  commas.
Examples:  "1,2,5,9","0-4,8-12".

Pero tu caso es un poco más complicado y puedes aprovechar esta característica:

Note: The day of  a command's execution can be specified by two fields day
of month, and day of week. If both fields are restricted (i.e., aren't *),
the command will be run when either  field matches the current time.
For example, "30  4  1,15  *  5" would cause a command to be run at 4:30 am
on the 1st and 15th of each month, plus every Friday.

Entonces, en tu caso, puedes escribir 0 9-5 8 * 1-5. Eso ejecutaría su comando cada 8 del mes y todos los días de lunes a viernes.

Otra solución es utilizar un test( man bash, sección EXPRESIONES CONDICIONALES y man date):

# Run on every second Saturday of the month:
   0 4 8-14 * *    test $(date +%u) -eq 6 && echo "2nd Saturday"

información relacionada