Find Linux Total Bandwidth in One Line

Posted on

Problem :

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.

Solution :

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

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

8.03 MiB

Leave a Reply

Your email address will not be published. Required fields are marked *