Skip to content

Instantly share code, notes, and snippets.

@Bazai
Created March 13, 2017 05:47
Show Gist options
  • Save Bazai/26e2a73e2b93df46c18a1da1b872fde8 to your computer and use it in GitHub Desktop.
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.
#!/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