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