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 如何根据日期输出到新的日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                <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>