ssh speed test
This commit is contained in:
86
web/ssh-speed-test
Executable file
86
web/ssh-speed-test
Executable file
@@ -0,0 +1,86 @@
|
||||
#!/bin/bash
|
||||
|
||||
_help() {
|
||||
echo '
|
||||
SSH performance test
|
||||
|
||||
args: [-s size] [-r repeats] user@host
|
||||
|
||||
Options:
|
||||
|
||||
-s default: 100MB, acceptable suffixes: M,G,T,P
|
||||
-r default: 1
|
||||
-d Download only
|
||||
-u Upload only
|
||||
'
|
||||
exit
|
||||
}
|
||||
|
||||
_size_in_bytes() {
|
||||
size=${size^^}
|
||||
if [[ ! ${size: -1} = "B" ]]; then
|
||||
size="${size}B"
|
||||
fi
|
||||
numeric=${size%??}
|
||||
suffix=${size: -2}
|
||||
onemb=$(( 1024**2 ))
|
||||
case $suffix in
|
||||
MB) bytes=$(( 1024**2 * $numeric )) ;;
|
||||
GB) bytes=$(( 1024**3 * $numeric )) ;;
|
||||
TB) bytes=$(( 1024**4 * $numeric )) ;;
|
||||
PB) bytes=$(( 1024**5 * $numeric )) ;;
|
||||
*) echo "Cant parse size"; exit 1; ;;
|
||||
esac
|
||||
megabytes=$(( $bytes / (1024**2) ))
|
||||
|
||||
}
|
||||
|
||||
size=100MB
|
||||
repeats=1
|
||||
upload=1
|
||||
download=1
|
||||
|
||||
shift_arg=0
|
||||
for (( i=1; i<=$#; i++ )); do
|
||||
value=${!i}
|
||||
j=$(( i + 1 ))
|
||||
if [[ $shift_arg -eq 1 ]]; then
|
||||
shift_arg=0
|
||||
continue
|
||||
fi
|
||||
if [[ "$value" = "--help" ]]; then _help; fi
|
||||
if [[ "${value}" = "-"* ]]; then
|
||||
[[ "$value" = -h ]] && { _help; }
|
||||
[[ "$value" = -s ]] && { size=${!j}; }
|
||||
[[ "$value" = -r ]] && { repeats=${!j}; }
|
||||
[[ "$value" = -u ]] && { download=0; continue; }
|
||||
[[ "$value" = -d ]] && { upload=0; continue; }
|
||||
shift_arg=1
|
||||
continue
|
||||
else
|
||||
host="$value"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if [[ -z "$host" ]]; then
|
||||
_help
|
||||
fi
|
||||
_size_in_bytes
|
||||
|
||||
|
||||
if [[ $download -eq 1 ]]; then
|
||||
echo "Downloading $size repeated $repeats times:"
|
||||
for i in $( seq $repeats ); do
|
||||
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:"
|
||||
for i in $( seq $repeats ); do
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user