You are not logged in.
Hi,
I want to write a simple program or script that does the following:
Say I am downloading something. I want the program / script to recognize when the download rate drops below a certain
threshold (say, 10kb/s) and do something (say, shutdown the computer).
Can someone point me to the right direction?
How can I know the download rate?
Thanks
fiod
Last edited by fiod (2009-10-24 08:49:40)
Offline
Total downloaded is in /sys/class/net/eth0/statistics/rx_bytes (uploaded is tx_bytes)
old=0;while sleep 5; do new=$(cat /sys/class/net/eth0/statistics/rx_bytes); diff=$(( (new-old)/5120 )); echo $diff kb/s; [ $diff -lt 10 ] && echo TERMINATE; old=$new; done
Offline
Thanks a lot!
I will try figuring it out.
Whats the 5120 in "(new-old)/5120" by the way?
fiod
Offline
5(seconds) * 1024(kb)
Offline
It actually didn't work.
I did the following:
#!/bin/bash
old=0;
while sleep 5; do
new=$(cat /sys/class/net/eth0/statistics/rx_bytes);
diff=$(( (new-old)/5120 ));
echo $diff kb/s;
[ $diff -lt 1000 ] && echo TERMINATE;
old=$new;
done
(changed 10 to 1000 in "$diff -lt 10" to make sure it works).
And I got the following output:
It didn't immediately told me that the download rate is below 1000, but after a few seconds I got the following output:
[fio@delltux /tmp]$ ./tempscript
0 kb/s
TERMINATE
0 kb/s
TERMINATE
0 kb/s
TERMINATE
The download rate all this time was around 200 KB/s.
Tnx
fiod
Offline
Do you use something other than eth0?
Offline
Sorry, my bad..
Didn't switch "eth0" to "eth1".
Thanks a lot!
fiod
Offline