Hello.
My workplace is unlimited, which sometimes I want to use. For example, to download a lot of music, so that he left it, forgot it for a couple of days, remembered, and it already swayed. The problem is that bezlimitka, nevertheless, is limited in speed (30Kb / s), and if you leave a download wget in the impudent, then no one will be happy about it.
I wrote a small script that pings Yandex, and based on this changes the download speed:
#!/bin/bash
limit =1
delay =5
num_of_pings =3
while true
do
# , . --limit-rate — . "&" , , wget background
wget -t0 -c --limit-rate= $limit -q ://__&
# , .
jobnum =`jobs %% | mawk '{if (NR==1) print $1}' | perl -pe 's/\[//; s/\]\+//' `
# wget' , .
sleep $delay <br>
# , wget . jobs, ( Running, wget' ).
if [ "`jobs % $jobnum | mawk '{if (NR==1) print $2}' `" == "Running" ]
then
# , .
kill % $jobnum
else
# , , while', .
break
fi
# , wget'
sleep 2
# . 300 , , .
if [ `ping -c $num_of_pings ya.ru | grep time= | mawk '{print $8}' | perl -pe 's/time=//' | mawk '$1 ~ // {sum += $1}; END {sum /= ' $num_of_pings '; print sum}' | perl -pe 's/\.[0-9]*//' ` -le 300 ]
then
# , . (20 ) .
limit =0
delay =20
else
# , . 5 ( 100b/s).
limit =100
delay =300
fi
done
This thing almost does not interfere with the work, except once every five minutes for 20 seconds. And that, only if you are not lucky to free the channel at that moment.
')
But problems, after all, are:
- When the channel is free, it is not used to its full capacity - several seconds are lost for idle, plus a little time for wget to restore the connection.
- This script basically will not work if the server from which we download files does not support resuming.
- If the script does still catch the channel, then you have to wait 20 seconds.
Actually, now a couple of questions:
Can anyone suggest a better and more correct way for such downloads?
How can you improve this script so that it becomes a good and correct way?
UPD: Slightly corrected the script. It now works with the specific job (job) it creates, and there are no more global killall wget. In addition, ping is now not one, but as much as you want.