I'd like to log cron output to a dated file —?/tmp/log/cron-2014-12-17.log
$ mkdir /tmp/log
$ chmod 777 /tmp/log
$ ls -lah /tmp/log
drwxrwxrwx 2 root root 4.0K Dec 17 21:51 .
Cron (via root
user)
* * * * * /usr/bin/php /path/to/script.php > /tmp/log/cron-$(date "+%F").log 2>&1
/tmp/log
remains empty after each minute.
If I run the script manually from command line a log file is created, and output is as expected.
// Running it manually as a CLI works fine, but not as a cron
$ /usr/bin/php /path/to/script.php > /tmp/log/cron-$(date "+%F").log 2>&1
Also, if I create a file and chmod 777 it, the cron will write output to this created file. It just won't create one on the fly.
// Let's create it first
$ touch /tmp/log/cron.log
$ chmod 777 /tmp/log/cron.log
// wait for the next minute...
$ tail -f /tmp/log/cron.log
output... output... output...
But this doesn't work for dynamic names like /tmp/log/cron-2014-12-17.log
.
What am I missing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…