Created
May 19, 2015 06:07
-
-
Save anupsabraham/fe1e0a492f17cb5bd158 to your computer and use it in GitHub Desktop.
Check if internet is up or down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((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