Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Automatically restart network on lost connection ' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Automatically restart network on lost connection
Authored by: wallybear on Apr 18, '12 09:01:45AM
Here is a single script to do it all, and includes the functionality of the missing script:
#!/bin/bash
# This script determines which script to run
# based on whether your running on
# ethernet or airport.
# Name check_internet_master.sh or similar
# Attach this script to launchctl to run automatically.

# Alter tobenotified to reflect you email address.
tobenotified='xxxx@xxx.com'

check_internet() {
	
IS=`/sbin/ping -c 5 74.125.226.18 | grep -c "64 bytes"`
if (test "$IS" -gt "2") then
       echo "Your internet connection appears to be working. Code" $IS
       internet_conn="1"
   exit
else
   echo "There appears to be a problem with your internet connection. Will check again in 10 seconds... Code" $IS
   internet_conn="0"
   sleep 5
   AA=`/sbin/ping -c 5 74.125.226.18 | grep -c "64 bytes"`
   if (test "$AA" -gt "2") then
       internet_conn="1"
       echo "Your internet connection appears to be working now. Code" $AA
       exit
   else
       echo "There is still a problem with your internet connection. Attempting to fix by ethernet restart... Code" $AA
       sudo ifconfig $1 down
       sleep 5
       sudo ifconfig $1 up
       echo "Your internet connection needed to be restarted" | mail -s "Internet Connection Down on $(date '+%m/%d/%y @ %H:%M:%S')" $tobenotified -f ipdown@no-reply.com -F "Ethernet Connection Problem"
   fi
fi

}

# alternative to get active network port:
# AI=`ifconfig | grep -B5 " active" | grep -m1  "^...:" | sed "s/\(.*\):.*/\\1/"`

AI=`route get 0.0.0.0 | grep -m1 "interface:" | awk '{print $2}'`
echo "check_internet_master has detected" $AI "as your primary network interface..."
check_internet $AI




[ Reply to This | # ]
Automatically restart network on lost connection
Authored by: robertcoogan on Apr 22, '12 10:32:55AM

Many, many, many thanks for this. My connection was dropping (seemingly) at random. I thought it was due to overheating, or possibly a bad Airport card (Apple tech support ruled this out). Since running this script I have seen it drop and restablish two times in the last day.

YOU ARE AWESOME!!!!




[ Reply to This | # ]
Automatically restart network on lost connection
Authored by: wallybear on Apr 23, '12 12:57:43PM
YOU ARE AWESOME!!!!

You're welcome (mmmhmm, I think I will forward this comment to my wife, she always doubted about this... :) )

[ Reply to This | # ]
Automatically restart network on lost connection
Authored by: rvamerongen on Apr 26, '12 08:20:57AM

Hi, nice script. Why not ping your modem first?
I do use this, because, when I can't get my modem then it is my mac. If it is the internet connection it keeps restarting for nothing when there is no internet. Also, when your mac is connected or has shares or connected to shares you will loose those as well, even when the local network works.
Luckily, not happened for three+ years for any internet failure, but my iMac has every day several times since 10.6.x

Also what is ' internet_conn="1" ' for?

The only thing what I would like to find out is, how can I get the used gate/router ip address from using a script at the mac it self ( localhost -> gate address). Any suggestions..

Edited on Apr 26, '12 08:59:33AM by rvamerongen



[ Reply to This | # ]