// post

GNU/Linux | Programación

Uso del comando date en cron

Si queremos crear un fichero de log con el resultado de un script que vamos a lanzar periódicamente usando cron, conviene tener en cuenta un detalle de sintaxis.


$ crontab -e

# m h  dom mon dow   command
00 03  * * * /ruta/script.sh > /ruta/fichero_`date +\%y_\%m_\%d`.log

Esto sería un ejemplo de la lista de tareas de cron, si os fijáis en el detalle de `date +\%d_\%m_\%y` se han escapado los símbolos de %. Esto se explica perfectamente en el man 5 crontab, pero lo escribo aquí para no olvidarme y por si de paso le sirve a alguien más.

The ‘‘sixth’’ field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file. Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input. There is no way to split a single command line onto multiple lines, like the shell’s trailing “\”.

Más información: cron y date.

Comentarios

Los comentarios están cerrados.

Los comentarios están cerrados. Si quieres contactar con el autor, dirígete a la sección de contacto.

Bienvenido a The Power of Mind

The Power of Mind es el blog personal de DraXus, orientado a temas de Informática, Software Libre e Internet. Más sobre el autor…

del.icio.us flickr plurk twitter skype
linkedin facebook tuenti lastfm youtube

Recomendados

Yo participo en el Software Freedom Day 2011
AndaluciaPeople.com
Alhambrismo.com

flickr

Switch to our mobile site