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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.checkint</string>
<key>LowPriorityIO</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/Users/matt/Documents/Scripts/check_internet_master.sh</string>
</array>
<key>StartInterval</key>
<integer>30</integer>
</dict>
</plist>

-----> This is what is needed to make it automatically run. Notice under ProgramArguments it references the restart check_internet_master.sh 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 check_internet_master.sh script. This should be a plaintext file.

# This script determines which interface to run
# on based on whether your running
# 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 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 ipdown@no-reply.com -F "Internet 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

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/check_internet_master.sh

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 | # ]