timeout for speedtest

This commit is contained in:
Ville Rantanen
2021-09-24 10:23:35 +03:00
parent 994cf31fcd
commit f74747f2f3

View File

@@ -1,15 +1,16 @@
#!/bin/bash
set -e
_help() {
echo '
SSH performance test
args: [-s size] [-r repeats] user@host
args: [-s size] [-r repeats] [-t timeout] [-d/-u] user@host
Options:
-s default: 100MB, acceptable suffixes: M,G,T,P
-r default: 1
-s size: default: 100MB, acceptable suffixes: M,G,T,P
-r repeats: default: 1
-t timeout: default: 60
-d Download only
-u Upload only
'
@@ -34,11 +35,14 @@ _size_in_bytes() {
megabytes=$(( $bytes / (1024**2) ))
}
_msg() {
echo "$1 $size repeated $repeats times, timeout ${timeout}s:"
}
size=100MB
repeats=1
upload=1
download=1
timeout=60
shift_arg=0
for (( i=1; i<=$#; i++ )); do
@@ -55,6 +59,7 @@ for (( i=1; i<=$#; i++ )); do
[[ "$value" = -r ]] && { repeats=${!j}; }
[[ "$value" = -u ]] && { download=0; continue; }
[[ "$value" = -d ]] && { upload=0; continue; }
[[ "$value" = -t ]] && { timeout=${!j}; }
shift_arg=1
continue
else
@@ -70,16 +75,16 @@ _size_in_bytes
if [[ $download -eq 1 ]]; then
echo "Downloading $size repeated $repeats times:"
_msg "Downloading"
for i in $( seq $repeats ); do
ssh -o 'Compression no' "$host" "dd if=/dev/zero bs=$onemb count=$megabytes 2>/dev/null" | \
timeout $timeout ssh -o 'Compression no' "$host" "dd if=/dev/zero bs=$onemb count=$megabytes 2>/dev/null" | \
pv -W -f -s ${bytes} > /dev/null
done
fi
if [[ $upload -eq 1 ]]; then
echo "Uploading $size repeated $repeats times:"
_msg "Uploading"
for i in $( seq $repeats ); do
dd if=/dev/zero bs=$onemb count=$megabytes 2>/dev/null | \
timeout $timeout dd if=/dev/zero bs=$onemb count=$megabytes 2>/dev/null | \
ssh -o 'Compression no' "$host" "cat | pv -W -f -s ${bytes} > /dev/null"
done
fi