创建空白文件的 Cron 作业

发布于 2024-12-07 06:22:26 字数 210 浏览 0 评论 0原文

我创建的 Cron 作业每次运行时都会自动创建一个空白文件。

有没有办法解决此问题,使其不会创建此文件?

以下是 cron 作业的命令:

/usr/bin/wget http://nitelife.wmetools.com/backend/index.php/ratings/overall_ratings_history

Cron jobs I created is automatically creating a blank file every time it's run.

Is there a way to fix this issue so that it doesn't create this file?

Below is the command for cron jobs:

/usr/bin/wget http://nitelife.wmetools.com/backend/index.php/ratings/overall_ratings_history

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

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

发布评论

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

评论(2

梦罢 2024-12-14 06:22:26

它正在下载一个空文件,因为这就是该 URL 为您提供的内容。如果您确定和/或不关心有一天该 URL 可能会发送一些数据(例如某种不常见的消息,例如错误),请在 wget 命令中添加“-O /dev/null”线。这将确保 wget 根本不会写入真正的文件。如果有 4xx 或 5xx 错误消息,您仍然会在来自 cron 的电子邮件中收到一些超出标准错误的信息,但如果任何消息通过超过 200 响应的正常 HTML 发送,则该消息将会丢失。

但这提出了一个问题,为什么首先“wget”该链接?如果您只想运行 .php 脚本而不关心其输出,我想第一个建议就足够了。否则,您可能需要一个简短的脚本,该脚本将使用 -O 写入临时文件,并测试非零文件大小(bash 中的“-s”),然后将文件移动到正确的位置,或删除0 长度的文件。这样,正常位置将只包含上次包含任何数据时的文件。

如果该 PHP 文件是您的,您可以对其进行编辑,使其不再提供 200 状态代码和 0 长度文档。有一个很少使用的“204 No Content”HTTP 状态代码。我还没有用 204 测试过 wget,但在这种情况下它确实不应该保存文件,也不应该被视为错误。

It's downloading an empty file because that's what that URL gives you. If you are sure and/or don't care about the possibility that some day, that URL may send some data (like some kind of infrequent message, like an error), add "-O /dev/null" to the wget command line. That will make sure that wget never writes a real file at all. If there's a 4xx or 5xx error message, you'll still get something over standard error into an email from cron, but if any message comes via a normal HTML over a 200 response, it would be lost.

That raises the question though, why "wget" that link in the first place? If you just want the .php script to run and don't care about its output, I suppose the first suggestion is sufficient. Otherwise, you may need a short script, which would use -O to write to a temp file, and test for a non-zero file size ("-s" in bash) and then move the file to the correct location, or delete the 0-length file. That way the normal location would only have the file from the last time it had any data in it.

If that PHP file is yours, you could edit it so that it doesn't give an 200 status code and 0 length document anymore. There's a rarely used "204 No Content" HTTP status code. I haven't tested wget with a 204, but it really shouldn't save a file in that case, nor should it be considered an error.

所有深爱都是秘密 2024-12-14 06:22:26

以下将删除 wget 创建的文件。

/usr/bin/wget -q --delete-after http://nitelife.wmetools.com/backend/index.php/ratings/overall_ratings_history

您可能会丢失这些文件中的信息。

Following will delete the file created by wget.

/usr/bin/wget -q --delete-after http://nitelife.wmetools.com/backend/index.php/ratings/overall_ratings_history

You may lose the information in these files.

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