Updated fixnet.sh to check for presence of USB device before checking for connectivity

This commit is contained in:
Ronald Farrer 2020-04-08 11:46:55 -07:00
parent 8efdeca1d4
commit 313684fe3e

View file

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# Version # Version
version=0.05 version=0.06
# A simple script that checks for connectivity (including working DNS resolution) # A simple script that checks for connectivity (including working DNS resolution)
# If no connectivity, reset tethering # If no connectivity, reset tethering
@ -21,22 +21,26 @@ CHECKWWW=www.google.com
SLEEPITOFF=60 SLEEPITOFF=60
while true; do while true; do
while true; do
# look for USB device
lsusb | grep $TETHERDEV > /dev/null lsusb | grep $TETHERDEV > /dev/null
# make sure there is a device connected before continuing
if (( $? )); then if (( $? )); then
echo "Tethering device not found! Sleeping..." echo "Tethering device not found! Sleeping 5s..."
sleep 5s sleep 5s
else else
echo "Tethering device present, continuing" echo "Tethering device present, continuing with network check..."
break break
fi fi
done done
while true; do # command to check for connectivity
curl --connect-timeout 10 $CHECKWWW > /dev/null 2>&1 curl --connect-timeout 10 $CHECKWWW > /dev/null 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
# No internet # No internet
echo "Network down, Houston we have a problem!" # FIXME: For debugging echo "Network down, resetting USB and restarting easytether!"
# Reset the USB device # Reset the USB device
usbreset $TETHERDEV usbreset $TETHERDEV
# Wait a few seconds for device to be ready again # Wait a few seconds for device to be ready again
@ -45,8 +49,9 @@ while true; do
easytether-usb easytether-usb
else else
# Internet working # Internet working
echo "Network up, all good in the hood!" # FIXME: For debugging echo "Network up!"
fi fi
echo "Sleeping $SLEEPITOFF before rechecking"
sleep $SLEEPITOFF sleep $SLEEPITOFF
done done