From 5e7ad09ff219ce6adf79cd6ff1e19ebf099c2c5e Mon Sep 17 00:00:00 2001 From: Teddysun Date: Tue, 1 May 2018 11:23:10 +0900 Subject: [PATCH] Fixed issues #23 Signed-off-by: Teddysun --- bench.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bench.sh b/bench.sh index 7a70f65..0b87add 100644 --- a/bench.sh +++ b/bench.sh @@ -32,15 +32,17 @@ next() { } speed_test_v4() { - local speedtest=$(wget -4O /dev/null -T300 $1 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}') - local ipaddress=$(ping -4 -c1 -n `awk -F'/' '{print $3}' <<< $1` | awk -F'[()]' '{print $2;exit}') + local output=$(wget -4O /dev/null -T300 $1 2>&1) + local speedtest=$(printf '%s' "$output" | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}') + local ipaddress=$(printf '%s' "$output" | awk -F'|' '/Connecting to .*\|([^\|]+)\|/ {print $2}') local nodeName=$2 printf "${YELLOW}%-32s${GREEN}%-24s${RED}%-14s${PLAIN}\n" "${nodeName}" "${ipaddress}" "${speedtest}" } speed_test_v6() { - local speedtest=$(wget -6O /dev/null -T300 $1 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}') - local ipaddress=$(ping -6 -c1 -n `awk -F'/' '{print $3}' <<< $1` | awk -F'[()]' '{print $2;exit}') + local output=$(wget -6O /dev/null -T300 $1 2>&1) + local speedtest=$(printf '%s' "$output" | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}') + local ipaddress=$(printf '%s' "$output" | awk -F'|' '/Connecting to .*\|([^\|]+)\|/ {print $2}') local nodeName=$2 printf "${YELLOW}%-32s${GREEN}%-24s${RED}%-14s${PLAIN}\n" "${nodeName}" "${ipaddress}" "${speedtest}" }