开发者

Cron outputs to log, is there a way to make the log dynamic?

开发者 https://www.devze.com 2023-02-19 05:59 出处:网络
I have a p开发者_开发技巧hp cron job that writes its output to a log file like this: crontab -l

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

精彩评论

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