I have the following script added to my rc.local file
#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
If I am connected to internet everything just works fine but if I am offline I get error
[FAIL] startpar: service(s) returned failure: rc.local ... failed!
What is wrong here and how could I fix it, I want rc.local to wait for internet connection before it continues to another script
As it appears to have solved your problem, this is how I would suggest writing your code:
Remember that
[
is not syntax, it is a command whose exit status determines whether yourwhile
loop continues or not. You should just test the exit status of the command you are trying to run directly.As for why this has solved your problem, to be honest I'm not sure. The error message that you have shown isn't really specific enough to indicate where the problem lies and I can't see anything actually wrong with what you did before. Perhaps you should try adding
set -xv
to yourrc.local
file to enable debugging.