Cron作业创建空文件每次运行 [英] Cron job creating empty file each time it runs

查看:124
本文介绍了Cron作业创建空文件每次运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php脚本我想运行每一分钟,看看是否有新闻稿需要张贴。我在cPanel中使用wget的cron命令,但我注意到(几天后),这是在主目录中创建一个空白文件,每次运行。



谢谢。

解决方案

当wget运行时,默认情况下,它会从我需要记住的内容生成一个输出文件。



您可能需要使用wget的一些选项并且使用 / dev / null 作为目标文件(这是一个特殊文件,它将写入)





从man w判断, -O - output-file 选项将是一个很好的候选项:



-O文件

- output-document = file

文档不会被写入



因此,您可能需要使用类似这样的文件:

  wget -O / dev / null http://www.example.com/your-script.php 



并且,btw,从crontab运行的脚本输出通常被重定向到日志文件 - 它总是可以帮助。 >

这样可能会有帮助:

  wget -O / dev / null http://www.example.com/your-script.php>> /YOUR_PATH_logfile.log 

您可能还想将错误输出重定向到另一个文件可以有用,帮助调试,一天出错):

  wget -O / dev / null http://www.example.com/your-script.php>> /YOUR_PATH/log-output.log 2>>> /YOUR_PATH/log-errors.log 


I have a php script I want to run every minute to see if there are draft news posts that need to be posted. I was using "wget" for the cron command in cPanel, but i noticed (after a couple days) that this was creating a blank file in the main directory every single time it ran. Is there something I need to stop that from happening?

Thanks.

解决方案

When wget runs, by default, it generates an output file, from what I need to remember.

You probably need to use some option of wget, to specify to which file it should write its output -- and use /dev/null as destination file (It's a "special file" that will "eat" everything you can write to it)


Judging from man wget, the -O or --output-file option would be a good candidate :

-O file
--output-document=file
The documents will not be written to the appropriate files, but all will be concatenated together and written to file.

so, you might need to use something like this :

wget -O /dev/null http://www.example.com/your-script.php


And, btw, the output of scripts run from the crontab is often redirected to a logfile -- it can always help.

Something like this might help, about that :

wget -O /dev/null http://www.example.com/your-script.php >> /YOUR_PATH_logfile.log

And you might also want to redirect the error output to another file (can be useful, to help with debugging, the day something goes wrong) :

wget -O /dev/null http://www.example.com/your-script.php >>/YOUR_PATH/log-output.log 2>>/YOUR_PATH/log-errors.log

这篇关于Cron作业创建空文件每次运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆