#!/bin/bash NIC="eth0" TX_Bytes() { /sbin/ifconfig "${NIC}"|egrep 'RX bytes'|awk '{print $2}'|cut -d':' -f2 } start_bandwidth_usage=$(TX_Bytes) sleep "${1}" new_bandwidth_usage=$(TX_Bytes) speed=$(($(($(($new_bandwidth_usage - $start_bandwidth_usage)) / ${1})) / 1024)) echo "${speed} KiB/s average in the past ${1} seconds"