繁体   English   中英

消耗带宽

[英]Consuming bandwidth

我知道如何编写一个基本的bash脚本,该脚本使用wget下载文件,但是如何在无限循环中运行此脚本以下载指定的文件,下载完成后将其删除,然后再次下载。

您正在寻找

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

这将不会保存文件,不会输出无用的信息,并将内容一遍又一遍地转储到/dev/null

编辑以仅消耗带宽,请使用ping -fping -f -s 65507

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

通过编程,一切皆有可能。 :)

如果要尝试最大程度地利用Internet带宽,则可以启动wget的许多过程,并让它们同时下载一些大磁盘映像文件,同时将一些大文件发送回某个服务器。

细节留给实现,但这是最大化带宽的一种方法。

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

$ netcat -l -p 12345

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

$ netcat 192.168.0.1 12345 < /dev/zero

我想用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

编辑:没关系,我想您一直在说它正在无休止地下载

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM