How to get download and upload bandwidth from Linux via shell?

1

I'd like to write a shell (bash) script that prints the system's download and/or upload capacities (in Kbps):

# Get download bandwidth
sh fetch-bandwidth.sh DOWNLOAD

> 556 Kbps download bandwidth

# Get upload bandwidth
sh fetch-bandwidth.sh UPLOAD

> 374 Kbps upload bandwidth

I can take care of the boilerplate stuff (validating arguments for input, formatting and printing output, etc.), however I'm clueless what to use for actually querying the system for the bandwidth values. Thanks in advance!

pnongrata

Posted 2012-12-23T23:01:00.823

Reputation: 2 212

Answers

1

iperf might be a start (I don't know if it works over the internet - I see no reason for it not to work):

Iperf was developed by NLANR/DAST as a modern alternative for measuring maximum TCP and UDP bandwidth performance. Iperf allows the tuning of various parameters and UDP characteristics. Iperf reports bandwidth, delay jitter, datagram loss.

Renan

Posted 2012-12-23T23:01:00.823

Reputation: 7 463

Thanks @Renan (+1) - definitely something worth looking at, but I was sort of hoping to find something baked into the distro. There aren't any "standard" Linux tools that provide this kind of information? Thanks again! – pnongrata – 2012-12-23T23:33:03.230

@pnongrata As far as I know, no. – Renan – 2012-12-24T00:10:31.517