Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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='email@email.com'
- # Change to your username
- user=username
- check_internet() {
- IS=`/sbin/ping -c 5 8.8.8.8 | grep -c "64 bytes"`
- if (test "$IS" -gt "2") then
- echo "Your internet connection appears to be working. Code" $IS
- echo "$(date '+%m/%d/%y @ %H:%M:%S') Your internet connection appears to be working. Code" $IS > /Users/$user/Library/Logs/netcheck.log
- internet_conn="1"
- exit
- else
- echo "There appears to be a problem with your internet connection. Will check again in 10 seconds... Code" $IS
- echo "$(date '+%m/%d/%y @ %H:%M:%S') There appears to be a problem with your internet connection. Will check again in 10 seconds... Code" $IS > /Users/$user/Library/Logs/netcheck.log
- internet_conn="0"
- sleep 5
- AA=`/sbin/ping -c 5 8.8.8.8 | grep -c "64 bytes"`
- if (test "$AA" -gt "2") then
- internet_conn="1"
- echo "Your internet connection appears to be working now. Code" $AA
- echo "$(date '+%m/%d/%y @ %H:%M:%S') Your internet connection appears to be working. Code" $AA > /Users/$user/Library/Logs/netcheck.log
- exit
- else
- echo "There is still a problem with your internet connection. Attempting to fix by service restart... Code" $AA
- echo "$(date '+%m/%d/%y @ %H:%M:%S') There is still a problem with your internet connection. Attempting to fix by service restart... Code" $AA > /Users/$user/Library/Logs/netcheck.log
- 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..."
- echo "$(date '+%m/%d/%y @ %H:%M:%S') check_internet_master has detected" $AI "as your primary network interface..." > /Users/$user/Library/Logs/netcheck.log
- check_internet $AI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement