Linux 在 crontab 中使用 wget 运行 PHP 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6531837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using wget in a crontab to run a PHP script
提问by JuCachalot
I set up a cron job on my Ubuntu server. Basically, I just want this job to call a php page on an other server. This php page will then clean up some stuff in a database. So I tought it was a good idea to call this page with wget and then send the result to /dev/null because I don't care about the output of this page at all, I just want it to do its database cleaning job. So here is my crontab:
我在我的 Ubuntu 服务器上设置了一个 cron 作业。基本上,我只是想让这个工作在其他服务器上调用一个 php 页面。然后这个 php 页面将清理数据库中的一些内容。所以我认为用 wget 调用这个页面然后将结果发送到 /dev/null 是个好主意,因为我根本不关心这个页面的输出,我只是想让它完成它的数据库清理工作。所以这是我的 crontab:
0 0 * * * /usr/bin/wget -q --post-data 'pass=mypassword' http://www.mywebsite.com/myscript.php > /dev/null 2>&1
(I post a password to make sure no one could run the script but me). It works like a charm except that wget writes each time an empty page in my user directory: the result of downloading the php page.
(我发布了一个密码以确保除了我之外没有人可以运行该脚本)。它就像一个魅力,除了 wget 每次在我的用户目录中写入一个空页面时:下载 php 页面的结果。
I don't understand why the result isn't send to /dev/null ? Any idea about the problem here? Thanks you very much!
我不明白为什么结果没有发送到 /dev/null ?对这里的问题有什么想法吗?非常感谢你!
采纳答案by Konerak
wget's output to STDOUT is it trying to make a connection, showing progress, etc.
wget 到 STDOUT 的输出是它试图建立连接、显示进度等。
If you don't want it to store the saved file, use the -O file
parameter:
如果您不希望它存储保存的文件,请使用 -O file
参数:
/usr/bin/wget -q --post-data -O /dev/null 'pass=mypassword' http://www.mywebsite.com/myscript.php > /dev/null 2>&1
Checkout the wget manpage. You'll also find the -q
option for completely disabling output to STDOUT (but offcourse, redirecting the output as you do works too).
查看wget 联机帮助页。您还将找到-q
完全禁用输出到 STDOUT的选项(但当然,在您执行时重定向输出也有效)。
回答by Gryphius
wget -O /dev/null ....
should do the trick
应该做的伎俩
回答by augusto
you can mute wget output with the --quiet option
您可以使用 --quiet 选项使 wget 输出静音
wget --quiet http://example.com