教程集 www.jiaochengji.com
教程集 >  脚本编程  >  shell  >  正文 测试多服务器网络速度的shell脚本

测试多服务器网络速度的shell脚本

发布时间:2014-10-18   编辑:jiaochengji.com
分享一个shell脚本,用于测试多台服务器的网络速度,有需要的朋友参考下。

面对多台服务器,甚至几百台服务器时,测试其网络速度,无疑需要使用脚本来代替人工了。
假设我们的测试地址为:http://server/speed_test_123.zip,测试前将speed_test_123.zip分发到各台机器上。
文件:/var/shell/vpn.txt 中保存着各服务器的域名,一行一个。
测试结果保存在:/var/shell/result.txt 文件中。

脚本如下:
 

复制代码 代码示例:

#!/bin/sh
#filename chk_speed.sh
#check network speed
#edit by www.jiaochengji.com

vpnlist="/var/shell/vpn.txt"
testfile="/speedtesting.zip"
result="/var/shell/result.txt"

echo "" > $result

cat $vpnlist | while read vpnserver
do
        url="http://$vpnserver$testfile"
        wget -o /tmp/vpn.log $url -O /dev/null

        speed=`cat /tmp/vpn.log | grep 'saved' | awk -F\ '{print $3}' | cut -c2-`
        unit=`cat /tmp/vpn.log | grep 'saved' | awk -F\ '{print $4}' | cut -c-2`

        if [ "$unit" == "MB" ]; then
                speed=`echo $speed*1024 | bc`
                unit="KB"
        fi

        echo "$url      $speed $unit/s" >> $result
        echo "$url      $speed $unit/s"
done

echo "VPN speed test finish,sort result display:"
cat $result | sort -k2 -rn

您可能感兴趣的文章:
测试多服务器网络速度的shell脚本
怎么让电脑网速提速
ping检测告警函数的shell脚本
win2003服务器安全设置之系统服务篇
检测linux网络服务是否开启的shell脚本(图文)
IE浏览器连接网络失败的原因及解决办法
扛住100亿次请求?我们来试一试
学python一定要学django吗
网页打开慢怎么办 网页打开慢解决办法
电脑宽带上网经常掉线解决方案

[关闭]
~ ~