scp linux两台服务器之间,利用scp测试两台Linux服务器之间传输速度的脚本

需要测试看看国内机房和美国机房之间传输文件的速度,找到如下脚本

#!/bin/bash

# scp-speed-test.sh

#

# Usage:

# ./scp-speed-test.sh user@hostname [test file size in MBs]

#

#############################################################

ssh_server=$1

test_file=".scp-test-file"

# Optional: user specified test file size in MBs

if test -z "$2"

then

# default size is 10MB

test_size="10"

else

test_size=$2

fi

# generate a file of all zeros

echo "Generating $test_size MB test file..."

dd if=/dev/zero of=$test_file bs=$(echo "$test_size*1024*1024" | bc) \

count=1 &> /dev/null

# upload test

echo "Testing upload to $ssh_server..."

up_speed=$(scp -v $test_file $ssh_server:$test_file 2>&1 | \

grep "Bytes per second" | \

sed "s/^[^0-9]*\([0-9.]*\)[^0-9]*\([0-9.]*\).*$/\1/g")

up_speed=$(echo "($up_speed/1000000)" | bc)

# download test

echo "Testing download from $ssh_server..."

down_speed=$(scp -v $ssh_server:$test_file $test_file 2>&1 | \

grep "Bytes per second" | \

sed "s/^[^0-9]*\([0-9.]*\)[^0-9]*\([0-9.]*\).*$/\2/g")

down_speed=$(echo "($down_speed/1000000)" | bc)

# clean up

echo "Removing test file on $ssh_server..."

ssh $ssh_server "rm $test_file"

echo "Removing test file locally..."

rm $test_file

# print result

echo ""

echo "Upload speed: $up_speed mbps"

echo "Download speed: $down_speed mbps"

This article is under CC BY-NC-SA 4.0 license.

Please quote the original link:https://www.liujason.com/article/395.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值