Php cron如何根据日期输出到新的日志文件?
我想将cron输出记录到一个有日期的文件-Php cron如何根据日期输出到新的日志文件?,php,cron,file-permissions,Php,Cron,File Permissions,我想将cron输出记录到一个有日期的文件-/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(通过rootuser) /tmp/log每分钟后都保持为空 如果我从命令行手动运行脚本,将创建一个日志文件,并按预期输出 // Running it manually as a CLI w
/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(通过root
user)
/tmp/log
每分钟后都保持为空
如果我从命令行手动运行脚本,将创建一个日志文件,并按预期输出
// 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
此外,如果我创建了一个文件并使用chmod 777将其保存,cron将向这个创建的文件写入输出。它只是不能在运行中创建一个
// 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...
但这不适用于动态名称,如/tmp/log/cron-2014-12-17.log
我遗漏了什么?这将解决您的问题:
0 0 * * * /some/path/to/a/file.php >> /tmp/log/cron-`date +\%F`.log 2>&1
这将解决您的问题:
0 0 * * * /some/path/to/a/file.php >> /tmp/log/cron-`date +\%F`.log 2>&1
可能重复的,等。可能重复的,等。