How Can I count the received data from the internet.

I want to run my bash script and count how many MB it receive.

It could be stats for whole system.

migrated from stackoverflow.com Dec 30 '12 at 16:24

This question came from our site for professional and enthusiast programmers.

  • This question is near serverfault, but stay linked to programmation... – F. Hauri Dec 30 '12 at 1:48
  • Ok. I'll remember. I'm sorry. – bluesm Dec 30 '12 at 1:54

watch your network devices


ip -s link show

cat /proc/net/dev

or better use iptables whith specific counters, that let you quantize by protocol, kind of connexions, durations, etc...

create a counter rule with no jump:

iptables -A INPUT -i eth0 -p tcp --dport 80

than watch them with

iptables -nvxL INPUT

(for playing with iptable, root access is needed).

  • Why amount of data in /proc/net/dev sometimes resets ? – bluesm Dec 30 '12 at 2:08
  • What do you mean by sometimes? As I know, driver module as to be unloaded in order to reset counters (ifdown ... rmmod ... modprobe ... ifup ). But maybe are you speaking about loop happening when all bits of integer counter are full (likely depending on your architecture). – F. Hauri Dec 30 '12 at 17:42

You can use pv command, see man pv(1) page. Also you can try different bandwidth monitoring tools.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.