Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # By Mark Hughes (www.markeh.me)
- #
- # See http://markeh.me/blog/dont-like-your-airport-being-disconnected-on-mac-i-have-the-solution/89
- #
- # First we want to see if we're connected to a network
- NETWORK_TEST=`networksetup -getairportnetwork en1 | grep "not associated"`;
- if [ "$NETWORK_TEST" = "" ]; then
- echo "AirPort is connected.";
- #echo "$NETWORK_TEST"; # Debugging purposes!
- else
- echo "AirPort is not connected to a network, wait 10 seconds and try again.";
- sleep 10;
- # Re-run the test
- NETWORK_TEST=`networksetup -getairportnetwork en1 | grep "not associated"`;
- if [ "$NETWORK_TEST" = "" ]; then
- echo "AirPort is now connected.";
- else
- echo "AirPort is not connected to a network, restarting the airport power.";
- networksetup -setairportpower en1 off
- # Just wait for everything to calm down, 1 second could probably do it even.
- sleep 2
- networksetup -setairportpower en1 on
- echo "Waiting 5 seconds for the AirPort to find something.";
- sleep 5
- NETWORK_TEST=`networksetup -getairportnetwork en1 | grep "not associated"`;
- if [ "$NETWORK_TEST" = "" ]; then
- echo "AirPort has now found a network.";
- # Take further action? Log something? Do something? Anything?
- else
- echo "No network could be found.";
- fi
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement