开发者

Cron job creating empty file each time it runs

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 r开发者_C百科an. 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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜