Skip to content

Instantly share code, notes, and snippets.

@anupsabraham
Created May 19, 2015 06:07
Show Gist options
  • Save anupsabraham/fe1e0a492f17cb5bd158 to your computer and use it in GitHub Desktop.
Save anupsabraham/fe1e0a492f17cb5bd158 to your computer and use it in GitHub Desktop.
Check if internet is up or down
((count = 100)) # Maximum number to try.
((internet = 0))
while [[ $count -ne 0 ]] ; do
ping -c 1 8.8.8.8 # Try once.
rc=$?
if [[ $internet -eq 0 ]] ; then
if [[ $rc -eq 0 ]] ; then
echo `say internet is up`
((internet = 1)) # If okay, flag to exit loop.
fi
else
if [[ $rc -ne 0 ]] ; then
echo `say internet is down again`
((internet = 0))
fi
fi
((count = count - 1)) # So we don't go forever.
done
echo `say run me again.`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment