Cron output & logging
A basic solution:
use
$()for executingdatecommand and return outputformat datetime to UTC, escape the
%character with\add
2>&1at the end for streaming bothstdoutandstderrinto that log file
Example:
* * * * * echo "Test crontab log" > /tmp/crontab.log.$(date --utc +\%Y\%m\%d_\%H\%M\%SZ) 2>&1Output:
ls -lh /tmp | grep log
-rw-rw-r-- 1 ubuntu ubuntu 17 May 4 05:06 crontab.log.20190504_050601Z
-rw-rw-r-- 1 ubuntu ubuntu 17 May 4 05:07 crontab.log.20190504_050701ZReference
Last updated