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: desepticon on Oct 31, '12 09:02:31AM

You need to put a plaintext file called "com.user.checkint.plist" into /Library/LaunchDaemons/
After the file is made and placed (contents below) From terminal, type this:
sudo chown root:wheel /Library/LaunchDaemons/com.user.checkint.plist
--then enter your administrator password
sudo chmod 644 /Library/LaunchDaemons/com.user.checkint.plist
--then enter your administrator password again
sudo chmod a+x /Library/LaunchDaemons/com.user.checkint.plist
--then enter administrator password

This is the contents of that file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

-----> This is what is needed to make it automatically run. Notice under ProgramArguments it references the restart which is located in a folder called Scripts inside my Documents folder (which is in my home folder "matt"). You need to change that string to reflect where you have stored the restart script. "matt" should be whatever your home folder is called. Create a folder called Scripts in your Documents folder and put it in there. That would be the easiest way. Just make sure to change "matt" to the name of your home folder. Below is the contents of the script. This should be a plaintext file.

# This script determines which interface to run
# on based on whether your running
# ethernet or airport.
# Name or similar
# Attach this script to launchctl to run automatically.

# Alter tobenotified to reflect you email address.

check_internet() {

IS=`/sbin/ping -c 5 | grep -c "64 bytes"`
if (test "$IS" -gt "2") then
echo "Your internet connection appears to be working. Code" $IS
echo "There appears to be a problem with your internet connection. Will check again in 10 seconds... Code" $IS
sleep 5
AA=`/sbin/ping -c 5 | grep -c "64 bytes"`
if (test "$AA" -gt "2") then
echo "Your internet connection appears to be working now. Code" $AA
echo "There is still a problem with your internet connection. Attempting to fix by service 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 -F "Internet Connection Problem"


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

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

After is is made and put in the right place you need to make it executable. Go back into terminal and type:

chmod a+x ~/Documents/Scripts/

Then restart and it should be working.

Also you may need to manually load the launchctl item. Type this into terminal:
sudo launchctl load -w /Library/LaunchDaemons/com.user.checkint.plist
---enter adminsitrator password
To unload:
sudo launchctl unload -w /Library/LaunchDaemons/com.user.checkint.plist

Then restart and it should be working.

Edited on Oct 31, '12 09:17:11AM by desepticon

[ Reply to This | # ]