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