脚本中的wget从cron打电话时不起作用

发布于 2025-01-27 13:56:47 字数 653 浏览 2 评论 0原文

我已经阅读了很多类似情况,但我的一生都无法弄清楚这个问题...

我在一个.sh脚本中运行了一个wget命令,该脚本从cron on Reboot on Reboot in Reboot中称为:

@reboot /home/user/reboot_script.sh

.sh。脚本以脚本开头

#!/bin/bash

,我已经完成了chmod +x reboot_script.sh

失败的行是:

要么

mac=$(</home/user/mac.txt)

可能无法将内容提供给wget中的变量

,或者

/usr/bin/wget "http://my.domain.com/$mac/line.txt" -O /home/user/line.txt 

如果我从命令行中运行脚本,它绝对可以正常工作,但是如果从重新启动的cron运行,脚本运行,但line.txt保存为一个空文件(0字节)。同样,如果直接从命令行运行,则可以正常运行。

我已经查看了文件权限,绝对路径,我能想到的一切,但是我已经盯着这个数小时了几个小时。

任何帮助将不胜感激。谢谢。

I've read a load of similar cases and can't for the life of me figure this one out...

I'm running a wget command inside a .sh script which is called from cron on reboot as follows:

@reboot /home/user/reboot_script.sh

The .sh script starts with

#!/bin/bash

And I have done chmod +x reboot_script.sh

The line that fails is :

Either

mac=$(</home/user/mac.txt)

Which may not be providing the content to the variable in the wget

OR

/usr/bin/wget "http://my.domain.com/$mac/line.txt" -O /home/user/line.txt 

If I run the script from command line, it works absolutely fine but if it runs from the cron on reboot, the script runs, but line.txt is saved as an empty file (0 bytes). Again, if run directly from command line, it works fine.

I've looked at file permissions, absolute paths, everything I can think of, but I've been staring at this for hours now.

Any help would be appreciated. Thanks.

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

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

发布评论

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

评论(1

绮筵 2025-02-03 13:56:47

@reboot在启动过程IMHO中还为时过早。您应该创建一个SystemD脚本来等待网络。

作为解决方法,您可以添加一个

sleep 30

until ping -c1 domain.com &>/dev/null; do
    sleep 5
done

或更高的方法

@reboot is too early in boot process IMHO. You should create a systemd script to wait network.

As a workaround, you can add a

sleep 30

or better:

until ping -c1 domain.com &>/dev/null; do
    sleep 5
done

before your wget

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