Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. #!/bin/bash
  2. # This script determines which script to run
  3. # based on whether your running on
  4. # ethernet or airport.
  5. # Name check_internet_master.sh or similar
  6. # Attach this script to launchctl to run automatically.
  7.  
  8. # Alter tobenotified to reflect you email address.
  9. tobenotified='email@email.com'
  10. # Change to your username
  11. user=username
  12. check_internet() {
  13.  
  14. IS=`/sbin/ping -c 5 8.8.8.8 | grep -c "64 bytes"`
  15. if (test "$IS" -gt "2") then
  16. echo "Your internet connection appears to be working. Code" $IS
  17. echo "$(date '+%m/%d/%y @ %H:%M:%S') Your internet connection appears to be working. Code" $IS > /Users/$user/Library/Logs/netcheck.log
  18. internet_conn="1"
  19. exit
  20. else
  21. echo "There appears to be a problem with your internet connection. Will check again in 10 seconds... Code" $IS
  22. 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
  23. internet_conn="0"
  24. sleep 5
  25. AA=`/sbin/ping -c 5 8.8.8.8 | grep -c "64 bytes"`
  26. if (test "$AA" -gt "2") then
  27. internet_conn="1"
  28. echo "Your internet connection appears to be working now. Code" $AA
  29. echo "$(date '+%m/%d/%y @ %H:%M:%S') Your internet connection appears to be working. Code" $AA > /Users/$user/Library/Logs/netcheck.log
  30. exit
  31. else
  32. echo "There is still a problem with your internet connection. Attempting to fix by service restart... Code" $AA
  33. 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
  34. sudo ifconfig $1 down
  35. sleep 5
  36. sudo ifconfig $1 up
  37. # 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"
  38. fi
  39. fi
  40.  
  41. }
  42.  
  43. # alternative to get active network port:
  44. # AI=`ifconfig | grep -B5 " active" | grep -m1 "^...:" | sed "s/\(.*\):.*/\\1/"`
  45.  
  46. AI=`route get 0.0.0.0 | grep -m1 "interface:" | awk '{print $2}'`
  47. echo "check_internet_master has detected" $AI "as your primary network interface..."
  48. 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
  49. check_internet $AI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement