Quick solution for pausing network hogs on tethered OSX devices

As an Australian, we can’t get away from mobile data caps. It seems to be a bit of a recent issue with some people on the mainland too 🙂 Here’s a quick script I wrote to stop myself forgetting about things a while back.

Add this to your crontab (crontab -e from the terminal):

* * * * * /Users/yaleman/killifmobile.sh

And put the following into a file (call it whatever you like, but the file path above must match it. Once you’ve made the file make sure to enable the execute bit by typing “chmod +x [filename]” in the terminal.

Ensure you put the name of the access point that you tether to after the = sign on the fourth line. I don’t know how it works with spaces and funny characters, but it should work OK.

#!/bin/bash

# name of the AP we want to avoid using
export AP=AP

CURRAP=`/usr/sbin/airport -I | grep " SSID" | awk '{ print $2 }'`
if [ "$CURRAP" == "$AP" ]
then
    # pause Backblaze
    /Library/Backblaze.bzpkg/bztransmit -pausebackup

    # deal with Dropbox
    if [ `ps aux | grep Dropbox | grep -v grep | wc -l` -gt 0 ]
        then
        kill `ps aux | grep Dropbox | grep -v grep | awk '{ print $2 }'`
    fi
else
    # if Dropbox isn't running open it again
    if [ `ps aux | grep Dropbox.app | egrep ^yaleman | grep -v grep | wc -l` -lt 1 ]
        then
        open /Applications/Dropbox.app/
    fi
fi

The script will kill Dropbox and pause Backblaze if it’s available. It’s fairly simple but seems to work for me.



#Backblaze #Dropbox #Mobile Data #Network #OSX #scripting