From f74747f2f35621dc801ae30374de30f5f36ccc59 Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Fri, 24 Sep 2021 10:23:35 +0300 Subject: [PATCH] timeout for speedtest --- web/ssh-speed-test | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/web/ssh-speed-test b/web/ssh-speed-test index 1a1f82a..24196f0 100755 --- a/web/ssh-speed-test +++ b/web/ssh-speed-test @@ -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