So I have written a shellscript, which is called in the startup process, and it works fine if the RPi is booted in a good environment (network is stable).
But if there has been a power outage bringing down the network router too, then the sending fails because the network is not connected to the Internet when the script runs...
So I want to enhance the script such that it can detect if the environment is OK (Internet accessible).
I have googled a bit and found that I should be able to add something like this to the top of the script to make it wait for the network before it executes the curl command towards the php script:
Code: Select all
#!/bin/bash
# Test connectivity to Internet at 1 minute intervals
while [ -z "$ONLINE" ]
do
ONLINE=$(ping -q -c 1 www.*******.com | grep "1 received")
if [ -z "$ONLINE" ]
then
sleep 60
fi
done
echo "We are on line!"
#Reporting code follows..
In this case the script echoes the message:
Code: Select all
ping: unknown host bogus.********.comI expect such a situation to be present when the mobile broadband router has not yet synced up following a power outage and there is no DNS server available.
I need to make sure this won't break the script and it is really hard to check too....
Is there a way to improve the on-line check such that it will not be affected by an error output from ping?