I need to monitor the amount of traffic that has passed through a given interface (mobile broadband dongle), so that I am informed when the total reaches (or nears) a given amount.
I have practically free mobile broadband up to a not very generous limit, and would like to start a script each time I want to use the dongle, and have it either warn me when it nears my limit, or tell me the total when I quit the script.
All I need help on right now is using the right command to record the total transfer in human readable values, i.e. as simple as "You have transferred 12.8Mb since monitoring started". I don't care about speed, utilisation or anything except cumulative total.
Once I have a way of calculating the total transfer, I can make happily throw in some ipfw commands to firewall the interface up and prevent further transfer until I say so.
I am using Mac OS X 10.7, but want to use standard terminal commands in a bash script (netstat, tcpdump, whatever is preinstalled) and not use a downloaded tool (even if it does the job perfectly - I need it in a script so I can put my own logic around it how I want).