Cron output & logging

A basic solution:

    use $() for executing date command and return output
    format datetime to UTC, escape the % character with \
    add 2>&1 at the end for streaming both stdout and stderr into that log file

Example:

1
* * * * * echo "Test crontab log" > /tmp/crontab.log.$(date --utc +\%Y\%m\%d_\%H\%M\%SZ) 2>&1
Copied!

Output:

1
ls -lh /tmp | grep log
2
3
-rw-rw-r-- 1 ubuntu ubuntu 17 May 4 05:06 crontab.log.20190504_050601Z
4
-rw-rw-r-- 1 ubuntu ubuntu 17 May 4 05:07 crontab.log.20190504_050701Z
Copied!

Reference

Last modified 2yr ago