-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspeed-test.sh
executable file
·54 lines (45 loc) · 1.38 KB
/
speed-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# speed-test.sh
#
# Test ssh connection speed by uploading and then downloading a 10000kB test
# file (optionally user-specified size)
#
# Usage:
# ./speed-test.sh user@hostname outfile [test file size in kBs]
#
ssh_server=$1
test_file=".scp-test-file"
# Optional: user specified test file size in kBs
if test -z "$3"
then
# default size is 10000kB ~ 10mB
test_size="10000"
else
test_size=$3
fi
out_file=$2
# generate a 10000kB file of all zeros
echo "Generating $test_size kB test file..."
`dd if=/dev/zero of=$test_file bs=$(echo "$test_size*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*0.0009765625*100.0+0.5)/1*0.01" | bc`
# download test
echo "Testing download to $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*0.0009765625*100.0+0.5)/1*0.01" | 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
`rm $out_file`
echo "Upload $up_speed kB/s" >> $out_file
echo "Download $down_speed kB/s" >> $out_file