Created
October 13, 2017 13:00
-
-
Save Gergling/57ad8a385510d7e0aae3fdc24f680e7f to your computer and use it in GitHub Desktop.
Bash scripts for restarting wifi when it fails.
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
#!/bin/bash | |
recent_restart=1 | |
while true; do | |
printf $(date +"%Y-%m-%d") | |
printf " " | |
printf $(date +"%H:%M:%S") | |
printf " " | |
if [[ $(ping -c 1 google.com) ]] > /dev/null 2>&1 ; then | |
if [ $recent_restart -eq 0 ] ; | |
then | |
printf "\n" | |
fi | |
recent_restart=1 | |
printf "Internet last up" | |
else | |
if [ $recent_restart -eq 1 ] | |
then | |
printf "\n" | |
bash restart.sh | |
printf "\n" | |
# echo "Would have restarted wifi" | |
recent_restart=0 | |
fi | |
printf "Internet last down" | |
fi | |
printf "\r" | |
sleep 1 | |
done |
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
#!/bin/bash | |
recent_restart=1 | |
while true; do | |
printf $(date +"%Y-%m-%d") | |
printf " " | |
printf $(date +"%H:%M:%S") | |
printf " " | |
if [[ $(ping -c 1 google.com) ]] > /dev/null 2>&1 ; then | |
if [ $recent_restart -eq 0 ] ; | |
then | |
printf "\n" | |
fi | |
recent_restart=1 | |
printf "Internet last up" | |
else | |
if [ $recent_restart -eq 1 ] | |
then | |
printf "\n" | |
bash restart.sh | |
printf "\n" | |
# echo "Would have restarted wifi" | |
recent_restart=0 | |
fi | |
printf "Internet last down" | |
fi | |
printf "\r" | |
sleep 1 | |
done | |
#!/bin/bash | |
# Check for internet connection. | |
if [[ $(ping -c 1 google.com) = "ping: cannot resolve google.com: Unknown host" ]] | |
then | |
echo "Internet is down" | |
else | |
echo "Internet is up" | |
fi | |
#!/bin/bash | |
# get current wifi device | |
CURRENT_DEVICE=$(networksetup -listallhardwareports | awk '$3=="Wi-Fi" {getline; print $2}') | |
echo "Current Wi-Fi Device = '$CURRENT_DEVICE'" | |
# turn off wifi | |
networksetup -setairportpower $CURRENT_DEVICE off | |
#!/bin/bash | |
# get current wifi device | |
CURRENT_DEVICE=$(networksetup -listallhardwareports | awk '$3=="Wi-Fi" {getline; print $2}') | |
echo "Current Wi-Fi Device = '$CURRENT_DEVICE'" | |
# turn on wifi | |
networksetup -setairportpower $CURRENT_DEVICE on | |
#!/bin/bash | |
# get current wifi device | |
CURRENT_DEVICE=$(networksetup -listallhardwareports | awk '$3=="Wi-Fi" {getline; print $2}') | |
echo "Current Wi-Fi Device = '$CURRENT_DEVICE'" | |
echo "Switching off wifi." | |
# turn off wifi | |
networksetup -setairportpower $CURRENT_DEVICE off | |
echo "Switching on wifi." | |
# turn on wifi | |
networksetup -setairportpower $CURRENT_DEVICE on | |
#!/bin/bash | |
# Check for internet connection. | |
if [[ $(ping -c 1 google.com) = "ping: cannot resolve google.com: Unknown host" ]] | |
then | |
echo "Internet is down" | |
else | |
echo "Internet is up" | |
fi |
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
#!/bin/bash | |
# get current wifi device | |
CURRENT_DEVICE=$(networksetup -listallhardwareports | awk '$3=="Wi-Fi" {getline; print $2}') | |
echo "Current Wi-Fi Device = '$CURRENT_DEVICE'" | |
# turn off wifi | |
networksetup -setairportpower $CURRENT_DEVICE off |
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
#!/bin/bash | |
# get current wifi device | |
CURRENT_DEVICE=$(networksetup -listallhardwareports | awk '$3=="Wi-Fi" {getline; print $2}') | |
echo "Current Wi-Fi Device = '$CURRENT_DEVICE'" | |
# turn on wifi | |
networksetup -setairportpower $CURRENT_DEVICE on |
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
#!/bin/bash | |
# get current wifi device | |
CURRENT_DEVICE=$(networksetup -listallhardwareports | awk '$3=="Wi-Fi" {getline; print $2}') | |
echo "Current Wi-Fi Device = '$CURRENT_DEVICE'" | |
echo "Switching off wifi." | |
# turn off wifi | |
networksetup -setairportpower $CURRENT_DEVICE off | |
echo "Switching on wifi." | |
# turn on wifi | |
networksetup -setairportpower $CURRENT_DEVICE on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment