我继续在rc.local中收到错误

时间:2014-12-04 11:22:00

标签: linux bash raspbian rc

我将以下脚本添加到我的rc.local文件

#wait until the internet connection is ready
wget -q --tries=10 --timeout=20 -O - http://google.com > /dev/null
while [ $? -ne 0 ]; do
        printf "Waiting for internet connection"
        sleep  10;
        wget -q --tries=10 --timeout=20 -O - http://google.com > /dev/null;

done

如果我连接到互联网,一切正常,但如果我离线,我会收到错误

[FAIL] startpar: service(s) returned failure: rc.local ... failed!

这里有什么问题,如何修复它,我希望rc.local在继续使用另一个脚本之前等待互联网连接

1 个答案:

答案 0 :(得分:2)

由于它似乎已经解决了您的问题,因此我建议您编写代码:

while ! wget -q --tries=10 --timeout=20 -O - http://google.com > /dev/null; do
    echo 'Waiting for internet connection'
    sleep 10
done

请记住,[不是语法,它是一个退出状态决定您的while循环是否继续的命令。您应该只测试您尝试直接运行的命令的退出状态。

至于为什么这已经解决了你的问题,说实话我不确定。您显示的错误消息并不是非常具体,足以指出问题出在哪里,我无法看到您之前所做的事情出现了什么问题。也许您应该尝试将set -xv添加到rc.local文件中以启用调试。