1. <small id='XFFfV'></small><noframes id='XFFfV'>

  2. <legend id='XFFfV'><style id='XFFfV'><dir id='XFFfV'><q id='XFFfV'></q></dir></style></legend>
    <i id='XFFfV'><tr id='XFFfV'><dt id='XFFfV'><q id='XFFfV'><span id='XFFfV'><b id='XFFfV'><form id='XFFfV'><ins id='XFFfV'></ins><ul id='XFFfV'></ul><sub id='XFFfV'></sub></form><legend id='XFFfV'></legend><bdo id='XFFfV'><pre id='XFFfV'><center id='XFFfV'></center></pre></bdo></b><th id='XFFfV'></th></span></q></dt></tr></i><div id='XFFfV'><tfoot id='XFFfV'></tfoot><dl id='XFFfV'><fieldset id='XFFfV'></fieldset></dl></div>

      <bdo id='XFFfV'></bdo><ul id='XFFfV'></ul>
    <tfoot id='XFFfV'></tfoot>

      cron 如何根据日期输出到新的日志文件?

      How can cron output to a new log file based on date?(cron 如何根据日期输出到新的日志文件?)

        <legend id='6Ez2H'><style id='6Ez2H'><dir id='6Ez2H'><q id='6Ez2H'></q></dir></style></legend>
      • <i id='6Ez2H'><tr id='6Ez2H'><dt id='6Ez2H'><q id='6Ez2H'><span id='6Ez2H'><b id='6Ez2H'><form id='6Ez2H'><ins id='6Ez2H'></ins><ul id='6Ez2H'></ul><sub id='6Ez2H'></sub></form><legend id='6Ez2H'></legend><bdo id='6Ez2H'><pre id='6Ez2H'><center id='6Ez2H'></center></pre></bdo></b><th id='6Ez2H'></th></span></q></dt></tr></i><div id='6Ez2H'><tfoot id='6Ez2H'></tfoot><dl id='6Ez2H'><fieldset id='6Ez2H'></fieldset></dl></div>
      • <tfoot id='6Ez2H'></tfoot>

        <small id='6Ez2H'></small><noframes id='6Ez2H'>

          <tbody id='6Ez2H'></tbody>

            • <bdo id='6Ez2H'></bdo><ul id='6Ez2H'></ul>

              1. 本文介绍了cron 如何根据日期输出到新的日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想将 cron 输出记录到一个过时的文件中 — /tmp/log/cron-2014-12-17.log

                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(通过root 用户)

                Cron (via root user)

                * * * * * /usr/bin/php /path/to/script.php > /tmp/log/cron-$(date "+%F").log 2>&1
                

                /tmp/log 每分钟后保持为空.

                如果我从命令行手动运行脚本,则会创建一个日志文件,并且输出符合预期.

                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
                

                此外,如果我创建一个文件并 chmod 777 它,cron 将输出写入这个创建的文件.它只是不会即时创建一个.

                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...
                

                但这不适用于 /tmp/log/cron-2014-12-17.log 之类的动态名称.

                But this doesn't work for dynamic names like /tmp/log/cron-2014-12-17.log.

                我错过了什么?

                推荐答案

                这将解决您的问题:

                0 0 * * * /some/path/to/a/file.php >> /tmp/log/cron-`date +\%F`.log 2>&1
                

                这篇关于cron 如何根据日期输出到新的日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                How to parse django style template tags(如何解析 django 样式模板标签)
                What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                php in background exec() function(php 后台 exec() 函数)
                <legend id='3fQuE'><style id='3fQuE'><dir id='3fQuE'><q id='3fQuE'></q></dir></style></legend>

                      <bdo id='3fQuE'></bdo><ul id='3fQuE'></ul>
                      <i id='3fQuE'><tr id='3fQuE'><dt id='3fQuE'><q id='3fQuE'><span id='3fQuE'><b id='3fQuE'><form id='3fQuE'><ins id='3fQuE'></ins><ul id='3fQuE'></ul><sub id='3fQuE'></sub></form><legend id='3fQuE'></legend><bdo id='3fQuE'><pre id='3fQuE'><center id='3fQuE'></center></pre></bdo></b><th id='3fQuE'></th></span></q></dt></tr></i><div id='3fQuE'><tfoot id='3fQuE'></tfoot><dl id='3fQuE'><fieldset id='3fQuE'></fieldset></dl></div>
                      <tfoot id='3fQuE'></tfoot>

                        <small id='3fQuE'></small><noframes id='3fQuE'>

                            <tbody id='3fQuE'></tbody>