Find Linux Total Bandwidth in One Line

2

Is there a command to find the total bandwidth used by a Linux box since startup, that returns one line?

The reason I'm asking is I'd like to call this shell not using a terminal and output the results through the web, rather than having a nice animating terminal.

Alfo

Posted 2012-08-19T07:33:13.537

Reputation: 166

would something like http://bandwidthd.sourceforge.net/ work instead? Its not a cli application, but you could use to do what you wanted

– Journeyman Geek – 2012-08-19T07:39:57.963

Answers

1

Try this:

netstat -N -i | awk '{if ($1 > 0 && $4 > 0) print $1,$4,$8}' | grep -i -v name | uniq

The output is like this:

Iface RX-OK TX-OK eth0 16257756 24735708 lo 15049 15049

(Up and Down in Bytes, by interface)

EDIT: After playing for a while:

netstat -i | awk '{print ($4+$8)}'

Is shows only the sum(in bytes) of every interface:

[claudiop@Workstation]# netstat -i | awk '{print ($4+$8)}'

0 0 40994492 30102

(I don't know from where came the "0"s, but you can easly filter the output)

Source

SOMN

Posted 2012-08-19T07:33:13.537

Reputation: 891

1

vnstat | awk '$7~/total/ {print $8,$9}' will output something like this:

8.03 MiB

pelz

Posted 2012-08-19T07:33:13.537

Reputation: 11

1It gives no output here. – SOMN – 2012-08-19T08:25:04.130

Did you install vnstat? Also, for the first few minutes after installation it won't display any data. – pelz – 2012-08-19T08:29:01.690

If i didn't it had an output like this: "bash: vnstat: command not found", but it simply gives no output. I have vnstat, and i am using arch. – SOMN – 2012-08-19T08:30:34.247