消耗带宽

时间:2010-07-29 14:56:50

标签: linux bash command-line ubuntu debian

我知道如何编写一个使用wget下载文件的基本bash脚本,但是如何在无限循环中运行它来下载指定文件,在下载完成后删除它,然后再次下载。< / p>

5 个答案:

答案 0 :(得分:5)

你正在寻找

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

这不会保存文件,也不会输出无用的信息,并在/dev/null

中一遍又一遍地转储内容

修改以消耗带宽,使用ping -fping -f -s 65507

答案 1 :(得分:3)

如果您的目标是最大化带宽,尤其是出于基准测试的目的,请使用iperf。您在服务器和客户端上运行iperf,它将使用您指定的协议和参数测试您的带宽。它可以测试单向或双向吞吐量,并可以选择尝试实现“目标”带宽利用率(即3Mbps)。

答案 2 :(得分:1)

编程可以实现一切。 :)

如果你想尝试最大化你的互联网带宽,你可以启动许多wget进程,让他们同时下载一些大磁盘映像文件,同时将一些巨大的文件发送回某些服务器

详细信息留待实施,但这是一种最大化带宽的方法。

答案 3 :(得分:1)

如果您想要消耗网络带宽,则需要另一台计算机。然后从计算机A,IP 192.168.0.1,监听端口(例如12345)。

$ netcat -l -p 12345

然后,从另一台计算机向其发送数据。

$ netcat 192.168.0.1 12345 < /dev/zero

答案 4 :(得分:0)

我更喜欢使用curl来进行wget。它更具可编辑性。这是我编写的bash脚本的一个问题,它检查SVN版本,然后让用户选择下载稳定版或最新版。然后它解析出文件,将“用户设置”与脚本的其余部分分开。

     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">"/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">"./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">"./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">"./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">"./mythicalSetup.sh"
    chmod +x "./mythicalSetup.sh"
    ./mythicalSetup.sh
    exit 0

fi

编辑:我知道你认为它是在无限循环中下载的