Created
March 19, 2023 16:13
-
-
Save davidair/64cfb6afa601e4fdd73e30b94c218a2b to your computer and use it in GitHub Desktop.
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 | |
# Inspired by https://raspberrypi.stackexchange.com/a/28047/127204 | |
MY_PATH="`dirname \"$0\"`" | |
LOG_PATH="/home/log/network.log" | |
now=$(date +"%m-%d %r") | |
# Which Interface do you want to check | |
wlan='wlan0' | |
# Which address do you want to ping to see if you can connect | |
pingip='8.8.8.8' | |
# Perform the network check and reset if necessary | |
/bin/ping -c 2 -I $wlan $pingip > /dev/null 2> /dev/null | |
if [ $? -ge 1 ] ; then | |
echo "$now Network is DOWN. Performing a reset" >> $LOG_PATH | |
systemctl restart dhcpcd.service | |
else | |
echo "$now Network is UP." >> $LOG_PATH | |
fi | |
logrotate $MY_PATH/logrotate.d/wifi_reset -s $MY_PATH/logrotate.d/status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment