Cron outputs to log, is there a way to make the log dynamic?
I have a p开发者_开发技巧hp cron job that writes its output to a log file like this:
crontab -l
* * * * * php -f /var/www/cron.php >> /tmp/crons/cron.log
Is there a way of making the log output file dynamic, so that it could write to date('Y-m')
.cron.log?
I'm not sure what cron uses to execute the commands, but in bash you could use backticks. So, with your crontab like this:
* * * * * bash /your/script.sh
and /your/script.sh containing this:
#!/bin/bash
php -f /var/www/cron.php >> /tmp/crons/`date +%Y-%m`.cron.log
you'll get that which you desire.
精彩评论