开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜