Skip to content

Instantly share code, notes, and snippets.

@davidair
Created March 19, 2023 16:13
Show Gist options
  • Save davidair/64cfb6afa601e4fdd73e30b94c218a2b to your computer and use it in GitHub Desktop.
Save davidair/64cfb6afa601e4fdd73e30b94c218a2b to your computer and use it in GitHub Desktop.
#!/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