脚本中的wget从cron打电话时不起作用
我已经阅读了很多类似情况,但我的一生都无法弄清楚这个问题...
我在一个.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@reboot
在启动过程IMHO中还为时过早。您应该创建一个SystemD脚本来等待网络。作为解决方法,您可以添加一个
:
或更高的方法
@reboot
is too early in boot process IMHO. You should create a systemd script to wait network.As a workaround, you can add a
or better:
before your wget