I don't have anything written, but I've been poking around and found that the file /proc/net/dev contains a line for each interface, which contains, inter-alia, the number of bytes received and sent. This might be a starting point:
Code:
net_stats () {
iface=$(grep 'eth0:' /proc/net/dev) # assuming your connection is via eth0
iface=${iface#*:} # strip the eth0: prefix
rec=$(echo $iface | awk '{print $1}') # field 1 contains the bytes received
tran=$(echo $iface | awk '{print $9}') # field 9 contains the bytes sent
}
traffic_per_sec () {
net_stats
last_rec=$rec
last_tran=$tran
sleep 1
net_stats
traffic=$((($rec - $last_rec) + ($tran - $last_tran)))
}
You'd probably want a few zero readings (or a zero reading over a longer interval than 1 second) before deciding that a download has finished, rather than just paused for a while, though.