Skip to content

Instantly share code, notes, and snippets.

@geocine
Created July 22, 2013 03:13
Show Gist options
  • Save geocine/6051085 to your computer and use it in GitHub Desktop.
Save geocine/6051085 to your computer and use it in GitHub Desktop.
#!/bin/sh
# cron script for checking wlan connectivity
# change 192.168.1.1 to whatever IP you want to check.
IP_FOR_TEST="192.168.1.1"
PING_COUNT=1
PING="/bin/ping"
IFUP="/sbin/ifup"
IFDOWN="/sbin/ifdown --force"
INTERFACE="eth0"
FFLAG="/opt/check_lan/stuck.fflg"
# ping test
$PING -c $PING_COUNT $IP_FOR_TEST > /dev/null 2> /dev/null
if [ $? -ge 1 ]
then
logger "$INTERFACE seems to be down, trying to bring it up..."
if [ -e $FFLAG ]
then
logger "$INTERFACE is still down, REBOOT to recover ..."
rm -f $FFLAG 2>/dev/null
sudo reboot
else
touch $FFLAG
logger $(sudo $IFDOWN $INTERFACE)
sleep 10
logger $(sudo $IFUP $INTERFACE)
fi
else
# logger "$INTERFACE is up"
rm -f $FFLAG 2>/dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment