Created
December 21, 2020 16:51
-
-
Save funkyremi/ff999777d27ad893590c44b5cadc3430 to your computer and use it in GitHub Desktop.
Reconnect to wifi or ethernet when down
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 | |
LOGFILE=/var/log/network-monitor.log | |
if /sbin/ifconfig eth0 | grep -q "inet"; then | |
echo "$(date "+%m %d %Y %T") : Ethernet OK" | |
else | |
echo "$(date "+%m %d %Y %T") : Ethernet connection down! Attempting reconnection." >>$LOGFILE | |
/sbin/ifconfig eth0 up | |
OUT=$? | |
if [ $OUT -eq 0 ]; then | |
STATE=$(/sbin/ifconfig eth0 | grep "inet") | |
echo "$(date "+%m %d %Y %T") : Ethernet network connection reset." >>$LOGFILE | |
else | |
echo "$(date "+%m %d %Y %T") : Failed to reset ethernet connection" >>$LOGFILE | |
fi | |
fi | |
if /sbin/ifconfig wlan0 | grep -q "inet"; then | |
echo "$(date "+%m %d %Y %T") : Wifi OK" | |
else | |
echo "$(date "+%m %d %Y %T") : Wifi connection down! Attempting reconnection." >>$LOGFILE | |
/sbin/ifconfig wlan0 up | |
OUT=$? | |
if [ $OUT -eq 0 ]; then | |
STATE=$(/sbin/ifconfig wlan0 | grep "inet") | |
echo "$(date "+%m %d %Y %T") : Wifi network connection reset." >>$LOGFILE | |
else | |
echo "$(date "+%m %d %Y %T") : Failed to reset wifi connection" >>$LOGFILE | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment