-
Notifications
You must be signed in to change notification settings - Fork 0
/
scp_bwtest.sh
executable file
·57 lines (47 loc) · 1.15 KB
/
scp_bwtest.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
55
56
57
#!/usr/bin/env bash
if [[ -z $1 ]]
then
echo "./speedtest HOST"
exit 1
fi
HOST=$1
stamp="$(date -u +%s)"
MIN_WAIT=15
ULMB=10
DLMB=10
ULF="${ULMB}Mrandom"
DLF="${DLMB}Mrandom"
echo "Setting up files..."
dd if=/dev/urandom of=$ULF bs=1M count=5
dd if=/dev/urandom of=$DLF bs=1M count=10
scp $DLF $HOST:/tmp/
OF="speedtest-$HOST-$stamp.csv"
TESTCOUNT=0
while true;
do
TESTCOUNT=$(( TESTCOUNT + 1 ))
echo "Starting test $TESTCOUNT..."
echo "Upload test..."
test_start="$(date -u +%s)"
start_time="$(date -u +%s)"
scp $ULF $HOST:/dev/null
end_time="$(date -u +%s)"
ul_elapsed="$(($end_time-$start_time))"
ul_rate="$((1048576 * $ULMB * 8 / $ul_elapsed))"
echo -n "Download test..."
start_time="$(date -u +%s)"
scp $HOST:/tmp/$DLF /dev/null
end_time="$(date -u +%s)"
dl_elapsed="$(($end_time-$start_time))"
dl_rate="$((1048576 * $DLMB * 8 / $dl_elapsed))"
echo "$test_start,$ul_elapsed,$ul_rate,$dl_elapsed,$dl_rate" | tee -a $OF
sleep 1
test_end="$(date -u +%s)"
test_elapsed=$(($test_end - $test_start))
COOLDOWN=$(( $MIN_WAIT - $test_elapsed ))
if [[ $(( $COOLDOWN > 0 )) ]]
then
echo "Sleeping for $COOLDOWN seconds..."
sleep $COOLDOWN
fi
done