Code" $AA sudo ifconfig en0 down sleep 10 sudo ifconfig en0 up echo "Your internet connection needed to be restarted" | mail -s "Internet Connection Down on $(date '+%m/%d/%y %H:%M:%S')" $tobenotified -f -F "Ethernet Connection Problem" fifi=#!/bin/bash# Script to restart the airport if there is no internet connection# Name this check_internet2.sh# Alter tobenotified to reflect you email address.IS=`/sbin/ping -c 5 74.125.226.18 | grep -c "64 (test "$IS" -gt "2") then echo "Your internet connection appears to be working.
Code" $AA exit else echo "There is still a problem with your internet connection. Code" $IS internet_conn="0" sleep 10 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" $IS internet_conn="1" exitelse echo "There appears to be a problem with your internet connection. Launching matched script."./check_internet2.sh=#!/bin/bash# Script to restart the ethernet if there is no internet connection# Name this check_internet.sh# Alter tobenotified to reflect you email address.IS=`/sbin/ping -c 5 74.125.226.18 | grep -c "64 (test "$IS" -gt "2") then echo "Your internet connection appears to be working. Launching matched script."./check_internet.shelseecho "check_internet_master has detected" $AI "as your primary network interface. =#!/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.AI=`./active_interface.sh`if thenecho "check_internet_master has detected" $AI "as your primary network interface. With this setup, I find I am nearly impervious to lost connections. Alternatively, you could make an exception for ifconfig in your /etc/sudoers file by adding the line (if you run as admin - else put %users): %admin ALL= NOPASSWD: /sbin/ifconfigI don't think this is too much of a security issue. In order for ifconfig to run with out intervention, the script needs to be run as root. Make sure to chmod all the files executable and, unless the scripts are altered, they should also be run from the same folder. Of course you can always name these whatever you want, but be sure to put the path to them in the scripts. The third and fourth scripts should be called "check_internet.sh" and "check_internet2.sh". Attach it to lauchctl to do this automatically and never worry about a lost connection. This second script is what controls the rest.
Name the first script "active_interface.sh", and the second "check_internet_master.sh". Or, if you do not wish to receive e-mail, comment these parts out. These last two scripts can also be configured to send you an e-mail if this happens by altering the 'tobenotified" string to reflect your e-mail address in each of them. These third and fourth scripts restart either the Ethernet or AirPort connection respectively. This is called by the second script which determines whether to run a matched script for either the Ethernet or AirPort interfaces. The first script gets the active network interface.
HOW TO RESTART A MAC ON LOCAL NETWORK MANUAL
This is important for me because I often have to access files over the internet and if the connection has locked up there is no way for me to access them without manual intervention. (This is different from a router crash which requires a manual restart of the router - in my case an Airport Extreme.) I have developed some interconnected scripts that will automatically accomplish this task for me when attached to launchctl. Only restarting the Airport or Ethernet interfaces seem to resolve the issue in a timely manner. Often times, for whatever reason, the Internet connection on my Mac will lock up.