views:

115

answers:

5

Dear Community,

I know how to write a basic bash script which uses wget to download a file, but how do I run this in an endless loop to download the specified file, delete it when the download is complete, then download it again.

+1  A: 

Everything is possible with programming. :)

If you want to try and max out your internet bandwidth, you could start many many processes of wget and let them download some big disk image files at the same time, while at the same time sending some huge files back to some server.

The details are left for the implementation, but this is one method to max out your bandwidth.

LukeN
Sounds interesting, I know how to write basic scripts to use wget to download stuff, but how would I get it to download over and over again, deleting the version which has already been download, before downloading again?
oshirowanen
Updated original question.
oshirowanen
+1  A: 

In case you want to consume network bandwidth, you'll need another computer. Then from computer A, IP 192.168.0.1, listen on a port (e.g. 12345).

$ netcat -l -p 12345

Then, from the other computer, send data to it.

$ netcat 192.168.0.1 12345 < /dev/zero
Didier Trosset
I would like to try maxing out the internet connection.
oshirowanen
Updated original question.
oshirowanen
Consuming maximum bandwidth reliably is best done using `ping -f`. The question was about `wget`.
mvds
Could you please explain what ping -f does? i.e. how does it consume bandwidth?
oshirowanen
+5  A: 

you're looking for

while :
do
    wget -O - -q "http://some.url/" > /dev/null
done

this will not save the file, not output useless info, and dump the contents over and over again in /dev/null

edit to just consume bandwidth, use ping -f or ping -f -s 65507

mvds
I understand your first script, but what is the ping -f or ping -f -s 65507 doing?
oshirowanen
`-f` stands for flood pinging, and `-s 65507` set's the package size to 65507 byte
LukeN
indeed, and you won't make it any bigger, since 65507 + 8 (icmp header) + 20 (ip header) makes 65535 (or 0xffff), which is the largest ipv4 packet you can send. (note that it will be chopped up before going on the wire)
mvds
ping -f -s 1472 will probably work much better, since it won't fragment. (Assuming 1500 MTU, which is pretty normal nowadays. Might be higher if you're on a gigabit network with the server. Might be lower on PPPoE.)
derobert
@derobert do you have any idea what 8kb/s of '.' looks like in a terminal? ;-)
mvds
+3  A: 

If your goal is to max out your bandwidth, especially for the purposes of benchmarking, use iperf. You run iperf on your server and client, and it will test your bandwidth using the protocol and parameters you specify. It can test one-way or two-way throughput and can optionally try to achieve a "target" bandwidth utilization (i.e. 3Mbps).

Borealid
This is strange, I have no untrusted repositories on my home system, yet this package is coming up as being untrusted...
oshirowanen
@oshiorwanen : then either the package is unsigned, you actually have untrusted repositories, or something is wrong with your gpg. Regardless, it's a problem with your setup and not with the program. `iperf` is designed to do exactly what you're doing, and it does it both flexibly and well.
Borealid
@oshirowanen: Run another apt-get update, it may be that something went wrong downloading the Release file last time.
derobert
A: 

I perfer to use curl to wget. it is more editable. here is an excrpt from a bash script i wrote which checks the SVN version, and then gives the user a choice to download stable or latest. It then parses out the file, separating the "user settings" from the rest of the script.

     svnrev=`curl -s -m10  mythicallibrarian.googlecode.com/svn/trunk/| grep -m1 Revision |  sed s/"<html><head><title>mythicallibrarian - "/""/g|  sed s/": \/trunk<\/title><\/head>"/""/g`

if ! which librarian-notify-send>/dev/null && test "$LinuxDep" = "1"; then
    dialog --title "librarian-notify-send" --yesno "install librarian-notify-send script for Desktop notifications?" 8 25
    test $? = 0 && DownloadLNS=1 || DownloadLNS=0
    if [ "$DownloadLNS" = "1" ]; then
        curl "http://mythicallibrarian.googlecode.com/files/librarian-notify-send"&gt;"/usr/local/bin/librarian-notify-send"
        sudo chmod +x /usr/local/bin/librarian-notify-send
    fi
fi

if [ ! -f "./librarian" ]; then
    DownloadML=Stable
    echo "Stable `date`">./lastupdated
else

 lastupdated="`cat ./lastupdated`"
DownloadML=$(dialog --title "Version and Build options" --menu "Download an update first then Build mythicalLibrarian" 10 70 15 "Latest" "Download and switch to SVN $svnrev" "Stable" "Download and switch to last stable version"  "Build"  "using: $lastupdated" 2>&1 >/dev/tty) 
if [ "$?" = "1" ]; then
    clear
    echo "mythicalLibrarian was not updated."
    echo "Please re-run mythicalSetup."
        echo "Done."
    exit 1
fi
fi
clear
if [ "$DownloadML" = "Stable" ]; then
    echo "Stable "`date`>"./lastupdated"
    test -f ./mythicalLibrarian.sh && rm -f mythicalLibrarian.sh
    curl "http://mythicallibrarian.googlecode.com/files/mythicalLibrarian"&gt;"./mythicalLibrarian.sh"
    cat "./mythicalLibrarian.sh"| sed s/'   '/'\\t'/g |sed s/'\\'/'\\\\'/g   >"./mythicalLibrarian1" #sed s/"\\"/"\\\\"/g |
    rm ./mythicalLibrarian.sh
    mv ./mythicalLibrarian1 ./mythicalLibrarian.sh
    parsing="Stand-by Parsing mythicalLibrarian"
    startwrite=0
    test -f ./librarian && rm -f ./librarian
    echo -e 'mythicalVersion="'"`cat ./lastupdated`"'"'>>./librarian
    while read line
    do
        test "$line" = "########################## USER JOBS############################" && let startwrite=$startwrite+1
        if [ $startwrite = 2 ]; then
            clear
            parsing="$parsing""."
            test "$parsing" = "Stand-by Parsing mythicalLibrarian......." && parsing="Stand-by Parsing mythicalLibrarian"
            echo $parsing
            echo -e "$line" >> ./librarian
        fi
    done <./mythicalLibrarian.sh

    clear
    echo "Parsing mythicalLibrarian completed!"
    echo "Removing old and downloading new version of mythicalSetup..."
    test -f ./mythicalSetup.sh && rm -f ./mythicalSetup.sh
    curl "http://mythicallibrarian.googlecode.com/files/mythicalSetup.sh"&gt;"./mythicalSetup.sh"
    chmod +x "./mythicalSetup.sh"
    ./mythicalSetup.sh
    exit 0

fi
if [ "$DownloadML" = "Latest" ]; then
    svnrev=`curl -s  mythicallibrarian.googlecode.com/svn/trunk/| grep -m1 Revision |  sed s/"<html><head><title>mythicallibrarian - "/""/g| sed s/": \/trunk<\/title><\/head>"/""/g`
    echo "$svnrev "`date`>"./lastupdated"
    test -f ./mythicalLibrarian.sh && rm -f mythicalLibrarian.sh
    curl "http://mythicallibrarian.googlecode.com/svn/trunk/mythicalLibrarian"&gt;"./mythicalLibrarian.sh"
    cat "./mythicalLibrarian.sh"| sed s/'   '/'\\t'/g |sed s/'\\'/'\\\\'/g   >"./mythicalLibrarian1" #sed s/"\\"/"\\\\"/g |
    rm ./mythicalLibrarian.sh
    mv ./mythicalLibrarian1 ./mythicalLibrarian.sh
    parsing="Stand-by Parsing mythicalLibrarian"
    startwrite=0
    test -f ./librarian && rm -f ./librarian
    echo -e 'mythicalVersion="'"`cat ./lastupdated`"'"'>>./librarian
    while read line
    do
        test "$line" = "########################## USER JOBS############################" && let startwrite=$startwrite+1
        if [ $startwrite = 2 ]; then
            clear
            parsing="$parsing""."
            test "$parsing" = "Stand-by Parsing mythicalLibrarian......." && parsing="Stand-by Parsing mythicalLibrarian"
            echo $parsing
            echo -e "$line" >> ./librarian
        fi
    done <./mythicalLibrarian.sh

    clear
    echo "Parsing mythicalLibrarian completed!"
    echo "Removing old and downloading new version of mythicalSetup..."
    test -f ./mythicalSetup.sh && rm -f ./mythicalSetup.sh
    curl "http://mythicallibrarian.googlecode.com/svn/trunk/mythicalSetup.sh"&gt;"./mythicalSetup.sh"
    chmod +x "./mythicalSetup.sh"
    ./mythicalSetup.sh
    exit 0

fi

EDIT: NEVERMIND I THOUGHT YOU WERE SAYING IT WAS DOWNLOADING IN AN ENDLESS LOOP

Adam Outler