Please no constant ping google.com , you (your ip address) might get banned.
Yun losts connecting to Internet from time to time.
http://forum.arduino.cc/index.php?topic=203754.msg1507343#msg1507343
Yun internet-live-led
http://forum.arduino.cc/index.php?topic=209412.msg1541242#msg1541242
#!/bin/sh
HOSTS="8.8.8.8" #google's dns server
ping_attempts=1
sleep_time=5
while true
do
count=$(ping -c $ping_attempts $HOSTS | awk -F, '/received/{print $2*1}')
#echo $count
if [ $count -eq 0 ]; then
# no internet do clean job, kill bridge and your script
else
# check if your script is running , if not start your script
fi
sleep $sleep_time
done