Fixing Snow Leopard’s Wireless Dropping Issue

by Jason on April 4, 2010

Ever since upgrading to Snow Leopard I’ve had major issues with my wireless connectivity. I recently hooked up an old Mac Mini to my TV for the sole purpose of running Boxee and these wireless issues have plagued me.

I tried all of the “fixes” mentioned on forum posts including:

  1. Manually setting IP address & DNS in Network Settings
  2. Flushing DNS
  3. Restarting Airport (doesn’t help if you can’t connect in the first place)
  4. Resetting PRAM

All of the solutions would temporarily fix the problem but usually within 10 minutes the connection would drop again.

So, my solution was to write a simple bash script that checked for network connectivity and if none existed it would flush the DNS and restart the airport.

Simply place this script on your system and create a cron job to execute the script every minute.


#!/bin/bash

count=$(ping -c 1 'http://www.google.com' | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
	#no internet 
	
	#make sure connectivity isn't currently being restarted
        if [ ! -f /Users/[insert_your_user_here]/network_monitor.pid ]; then

                #create pid file so script doesn't continuously run
                #when being restarted
                echo "Creating PID"
                touch /Users/[insert_your_user_here]/network_monitor.pid;

                #log event
                echo "No Internet " `date` >> /Users/[insert_your_user_here]/network_monitor.log;

                #flush DNS
                echo "Flushing DNS"
                dscacheutil -flushcache;

                #restart airport
                echo "Restarting Airport"
                /usr/sbin/networksetup -setairportpower en1 on;

                #sleep for five seconds
                echo "Sleeping"
                sleep 5;

                #clear pid file
                echo "Clearing PID"
                rm -f /Users/[insert_your_user_here]/network_monitor.pid;
        fi
else
	#internet is good
	echo "Internet Live " `date` >> /Users/[insert_your_user_here]/network_monitor.log;
fi

2 comments

Hey is there anyway i can stop the script, i dont know much about computers but i typed what you wrote and now it says terminal bash… etc.. how can i cancel or stop the script? thanks

by steven on October 21, 2011 at 2:52 pm. #

Hi Steven,

The script executes quickly then stops. The fact that you are seeing terminal bash means it finished executing. The script is meant to be placed in a cron job and run every couple of minutes.

I would recommend reading about cron jobs if you are interested in setting that up.

In the meantime, you can click on the Terminal then press Command-Q and it will close the window.

by Jason on October 22, 2011 at 6:46 am. #

Leave your comment

Required.

Required. Not published.

If you have one.