如何设置 wget cron 作业命令

发布于 2024-12-14 14:05:07 字数 408 浏览 5 评论 0原文

如何设置 cron 作业命令来执行 URL?

/usr/bin/wget -q http://www.domain.com/cron_jobs/job1.php >/dev/null 2>&1

为什么我不能完成这个工作!?已经尝试了所有方法.. PHP 脚本应该发送一封电子邮件并创建一些文件,但没有完成

该命令返回以下内容:

Output from command /usr/bin/wget -q http://www.domain.com/cron_jobs/job1.php ..

No output generated

...但每次执行时它仍然在 /root 中创建一个空文件! ?为什么?

How to setup a cron job command to execute an URL?

/usr/bin/wget -q http://www.domain.com/cron_jobs/job1.php >/dev/null 2>&1

Why can't I make this work!? Have tried everything.. The PHP script should send an email and create some files, but none is done

The command returns this:

Output from command /usr/bin/wget -q http://www.domain.com/cron_jobs/job1.php ..

No output generated

... but it still creates an empty file in /root on each execute!? Why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

凑诗 2024-12-21 14:05:07

像这样使用curl:

/usr/bin/curl http://domain.com/page.php

不用担心输出,它会被忽略

Use curl like this:

/usr/bin/curl http://domain.com/page.php

Don't worry about the output, it will be ignored

带上头具痛哭 2024-12-21 14:05:07

我也有同样的问题。解决方案是了解 wget 输出两件事:url 请求的结果和有关其正在执行的操作的活动消息。

默认情况下,如果您不指定输出文件,它将在运行 wget 的当前文件夹中创建一个输出文件,该文件似乎以您的 url 中的文件命名。

如果你想指定不同的输出文件:

-O outputfile.txt 

将把url结果输出到outputfile.txt,覆盖那里的内容。

如果您希望附加到该文件,请写入 std out,然后从那里附加到该文件:
技巧如下:写入 std out 使用:

-O-

第二个破折号代替文件名,并告诉 wget 将 url 结果写入 std out。

然后使用附加语法,>>,附加到您选择的文件:

wget -O- http://www.invisibility.com >>/var/log/invisibility.log

小写 o,指定活动日志的位置,因此如果您希望记录 url 请求的活动,您可以:

wget -o http://someurl.com /var/log/activity.log

-q抑制活动消息的输出

wget -q http://someurl.com /var/log/activity.log

不会将任何活动记录到指定的文件中,我认为这是人们感到困惑的关键。

记住:
-O 是 --output-document 的简写
-o 是 --output-file 的简写,即活动日志。

I had the same problem. The solution is understanding that wget is outputting two things: the results of the url request AND activity messages about what it's doing.

By default, if you do not specify an output file, it will create one, seemingly named after the file in your url, in the current folder where wget is run.

If you want to specify a different output file:

-O outputfile.txt 

will output the url results to outputfile.txt, overrwriting what's there.

If you wish to append to that file, write to std out and then append to the file from there:
and here's the trick: to write to std out use:

-O-

the second dash is in lieu of a filename and tells wget to write the url results to std out.

then use the append syntax, >>, to append to a file of your choice:

wget -O- http://www.invisibility.com >>/var/log/invisibility.log

The lower case o, specifies the location of the activity log, so if you wish to log activity for the url request, you can:

wget -o http://someurl.com /var/log/activity.log

-q suppresses output of activity messages

wget -q http://someurl.com /var/log/activity.log

will not log any activity to the specified file, and I think that is the crux where people get confused.

Remember:
-O is shorthand for --output-document
-o is shorthand for --output-file, which is the activity log.

你列表最软的妹 2024-12-21 14:05:07

我花了几个小时才让它工作。感谢您写下解决方案的人们。
还需要确保检查是否需要单引号或双引号,否则会解析 url 错误,从而导致错误消息:

This Worked (using singlequotes):

/usr/bin/wget -O -q 'http://domain.com/cron-file.php'

This Gives Errors (using doublequotes):

/usr/bin/wget -O -q "http://domain.com/cron-file.php"

Don't Know if需要 /usr/bin/ 。了解如何执行 -O -q 顺序的不同方法。很难在网络上找到该主题的可靠权威来源。有很多不同的例子。

可以在此处找到在线 wget 手册,了解可用选项(但请检查正在使用的 Linux 发行版以获得最新版本):
http://unixhelp.ed.ac.uk/CGI/man-cgi?wget

Took me hours to get it working. Thank you for people writing down solutions.
One also needs to make sure to check whether single or double quotes are needed, otherwise it will parse the url wrong leading to error messages:

This worked (using single quotes):

/usr/bin/wget -O -q 'http://domain.com/cron-file.php'

This gave errors (using double quotes):

/usr/bin/wget -O -q "http://domain.com/cron-file.php"

Don't know if the /usr/bin/ is needed. Read about different ways of how to do the order of the -O -q. It is hard to find a reliable definitive source on the web for this subject. So many different examples.

An online wget manual can be found here, for the available options (but check with the Linux distro one is using for an up to date version):
http://unixhelp.ed.ac.uk/CGI/man-cgi?wget

多情出卖 2024-12-21 14:05:07

使用 wget 显示 HTML:

wget -qO- http://www.example.com

For use wget to display HTML:

wget -qO- http://www.example.com
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文