Since we’ve had London, our new iMac, I’ve noticed intermittent Airport connectivity problems. Occasionally it would just lose its connection, despite the Airport network still being available in the list. Selecting it again brings it right back up, but what was puzzling is why it was happening in the first place. And I’m not the only one who’s noticed this.
This only seems to happen when the computer is not in use; I’ve never had it drop while actually doing something on it. So this wouldn’t be a big deal except that a) I occasionally SSH to this machine from elsewhere, and b) my nightly backups require internet access to back up a couple remote servers and accounts.
While I still don’t have an explanation, I’ve come up with a work-around. The following script, run from cron, will check the interface status and restart it if needed.
#!/bin/bash -e ####################################### # Check Airport connection status ####################################### PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Config AIRPORT_IF="en1" ####################################### ADDR=`ipconfig getifaddr $AIRPORT_IF 2> /dev/null || echo 0` if [ "$ADDR" = "0" ]; then ifconfig $AIRPORT_IF down sleep 5 ifconfig $AIRPORT_IF up fi exit 0
I run this hourly from cron. Cron in OS X 10.4+ has been deprecated in favor of launchd, but you can still use /etc/crontab if you install Anacron, which is available via MacPorts (formerly DarwinPorts). I can’t be bothered to write a launchd job for what’s otherwise a one-liner in the system crontab:
# Check Airport connection 00 * * * * root /usr/local/sbin/airport-check.sh
This runs the script every hour, on the hour, to check whether the wireless connection is up and to bring it up if it isn’t. I also run this at the beginning of my backup job to ensure the network is available before the backup process needs to use it. If I am ever unable to reach the machine remotely, I only have to wait until the top of the hour to try again.