Created
March 13, 2017 05:47
-
-
Save Bazai/26e2a73e2b93df46c18a1da1b872fde8 to your computer and use it in GitHub Desktop.
Restarts wifi if no ping to google. Adapt it to Alfred App workflow for quick run.
This file contains 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
#!/bin/bash | |
((count = 4)) # Maximum number to try. | |
while [[ $count -ne 0 ]] ; do | |
ping -c 1 8.8.8.8 # Try once. | |
# ping -c 1 1.2.3.4 | |
rc=$? | |
if [[ $rc -eq 0 ]] ; then | |
((count = 1)) # If okay, flag to exit loop. | |
fi | |
((count = count - 1)) # So we don't go forever. | |
done | |
if [[ $rc -eq 0 ]] ; then # Make final determination. | |
echo 'Internet is ok' | |
else | |
networksetup -setairportpower airport off && networksetup -setairportpower airport on | |
echo 'Wi-Fi was restarted' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment