mirror of
https://github.com/masonr/yet-another-bench-script.git
synced 2025-11-11 01:10:06 +05:30
refactor: add check for 'shuf' inside 'check_command' function
This commit is contained in:
parent
0aa21fff5e
commit
fdf136e464
1 changed files with 52 additions and 48 deletions
100
yabs.sh
100
yabs.sh
|
|
@ -786,56 +786,60 @@ function iperf_test {
|
||||||
|
|
||||||
# attempt the iperf send test 3 times, allowing for a slot to become available on the
|
# attempt the iperf send test 3 times, allowing for a slot to become available on the
|
||||||
# server or to throw out any bad/error results
|
# server or to throw out any bad/error results
|
||||||
I=1
|
if check_command "shuf"; then
|
||||||
while [ $I -le 3 ]
|
I=1
|
||||||
do
|
while [ $I -le 3 ]
|
||||||
echo -en "Performing $MODE iperf3 send test to $HOST (Attempt #$I of 3)..."
|
do
|
||||||
# select a random iperf port from the range provided
|
echo -en "Performing $MODE iperf3 send test to $HOST (Attempt #$I of 3)..."
|
||||||
PORT=$(shuf -i "$PORTS" -n 1)
|
# select a random iperf port from the range provided
|
||||||
# run the iperf test sending data from the host to the iperf server; includes
|
PORT=$(shuf -i "$PORTS" -n 1)
|
||||||
# a timeout of 15s in case the iperf server is not responding; uses 8 parallel
|
# run the iperf test sending data from the host to the iperf server; includes
|
||||||
# threads for the network test
|
# a timeout of 15s in case the iperf server is not responding; uses 8 parallel
|
||||||
IPERF_RUN_SEND="$(timeout 15 "$IPERF_CMD" "$FLAGS" -c "$URL" -p "$PORT" -P 8 2> /dev/null)"
|
# threads for the network test
|
||||||
# check if iperf exited cleanly and did not return an error
|
IPERF_RUN_SEND="$(timeout 15 "$IPERF_CMD" "$FLAGS" -c "$URL" -p "$PORT" -P 8 2> /dev/null)"
|
||||||
if [[ "$IPERF_RUN_SEND" == *"receiver"* && "$IPERF_RUN_SEND" != *"error"* ]]; then
|
# check if iperf exited cleanly and did not return an error
|
||||||
# test did not result in an error, parse speed result
|
if [[ "$IPERF_RUN_SEND" == *"receiver"* && "$IPERF_RUN_SEND" != *"error"* ]]; then
|
||||||
SPEED=$(echo "${IPERF_RUN_SEND}" | grep SUM | grep receiver | awk '{ print $6 }')
|
# test did not result in an error, parse speed result
|
||||||
# if speed result is blank or bad (0.00), rerun, otherwise set counter to exit loop
|
SPEED=$(echo "${IPERF_RUN_SEND}" | grep SUM | grep receiver | awk '{ print $6 }')
|
||||||
[[ -z $SPEED || "$SPEED" == "0.00" ]] && I=$(( I + 1 )) || I=11
|
# if speed result is blank or bad (0.00), rerun, otherwise set counter to exit loop
|
||||||
else
|
[[ -z $SPEED || "$SPEED" == "0.00" ]] && I=$(( I + 1 )) || I=11
|
||||||
# if iperf server is not responding, set counter to exit, otherwise increment, sleep, and rerun
|
else
|
||||||
[[ "$IPERF_RUN_SEND" == *"unable to connect"* ]] && I=11 || I=$(( I + 1 )) && sleep 2
|
# if iperf server is not responding, set counter to exit, otherwise increment, sleep, and rerun
|
||||||
fi
|
[[ "$IPERF_RUN_SEND" == *"unable to connect"* ]] && I=11 || I=$(( I + 1 )) && sleep 2
|
||||||
echo -en "\r\033[0K"
|
fi
|
||||||
done
|
echo -en "\r\033[0K"
|
||||||
|
done
|
||||||
|
|
||||||
# small sleep necessary to give iperf server a breather to get ready for a new test
|
# small sleep necessary to give iperf server a breather to get ready for a new test
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
# attempt the iperf receive test 3 times, allowing for a slot to become available on
|
# attempt the iperf receive test 3 times, allowing for a slot to become available on
|
||||||
# the server or to throw out any bad/error results
|
# the server or to throw out any bad/error results
|
||||||
J=1
|
J=1
|
||||||
while [ $J -le 3 ]
|
while [ $J -le 3 ]
|
||||||
do
|
do
|
||||||
echo -n "Performing $MODE iperf3 recv test from $HOST (Attempt #$J of 3)..."
|
echo -n "Performing $MODE iperf3 recv test from $HOST (Attempt #$J of 3)..."
|
||||||
# select a random iperf port from the range provided
|
# select a random iperf port from the range provided
|
||||||
PORT=$(shuf -i "$PORTS" -n 1)
|
PORT=$(shuf -i "$PORTS" -n 1)
|
||||||
# run the iperf test receiving data from the iperf server to the host; includes
|
# run the iperf test receiving data from the iperf server to the host; includes
|
||||||
# a timeout of 15s in case the iperf server is not responding; uses 8 parallel
|
# a timeout of 15s in case the iperf server is not responding; uses 8 parallel
|
||||||
# threads for the network test
|
# threads for the network test
|
||||||
IPERF_RUN_RECV="$(timeout 15 "$IPERF_CMD" "$FLAGS" -c "$URL" -p "$PORT" -P 8 -R 2> /dev/null)"
|
IPERF_RUN_RECV="$(timeout 15 "$IPERF_CMD" "$FLAGS" -c "$URL" -p "$PORT" -P 8 -R 2> /dev/null)"
|
||||||
# check if iperf exited cleanly and did not return an error
|
# check if iperf exited cleanly and did not return an error
|
||||||
if [[ "$IPERF_RUN_RECV" == *"receiver"* && "$IPERF_RUN_RECV" != *"error"* ]]; then
|
if [[ "$IPERF_RUN_RECV" == *"receiver"* && "$IPERF_RUN_RECV" != *"error"* ]]; then
|
||||||
# test did not result in an error, parse speed result
|
# test did not result in an error, parse speed result
|
||||||
SPEED=$(echo "${IPERF_RUN_RECV}" | grep SUM | grep receiver | awk '{ print $6 }')
|
SPEED=$(echo "${IPERF_RUN_RECV}" | grep SUM | grep receiver | awk '{ print $6 }')
|
||||||
# if speed result is blank or bad (0.00), rerun, otherwise set counter to exit loop
|
# if speed result is blank or bad (0.00), rerun, otherwise set counter to exit loop
|
||||||
[[ -z $SPEED || "$SPEED" == "0.00" ]] && J=$(( J + 1 )) || J=11
|
[[ -z $SPEED || "$SPEED" == "0.00" ]] && J=$(( J + 1 )) || J=11
|
||||||
else
|
else
|
||||||
# if iperf server is not responding, set counter to exit, otherwise increment, sleep, and rerun
|
# if iperf server is not responding, set counter to exit, otherwise increment, sleep, and rerun
|
||||||
[[ "$IPERF_RUN_RECV" == *"unable to connect"* ]] && J=11 || J=$(( J + 1 )) && sleep 2
|
[[ "$IPERF_RUN_RECV" == *"unable to connect"* ]] && J=11 || J=$(( J + 1 )) && sleep 2
|
||||||
fi
|
fi
|
||||||
echo -en "\r\033[0K"
|
echo -en "\r\033[0K"
|
||||||
done
|
done
|
||||||
|
else
|
||||||
|
echo -e "\nWarning: 'shuf' command not found. Skipping iperf network tests..."
|
||||||
|
fi
|
||||||
|
|
||||||
# Run a latency test via ping -c1 command -> will return "xx.x ms"
|
# Run a latency test via ping -c1 command -> will return "xx.x ms"
|
||||||
[[ -n $LOCAL_PING ]] && LATENCY_RUN="$(ping -c1 "$URL" 2>/dev/null | grep -o 'time=.*' | sed s/'time='//)"
|
[[ -n $LOCAL_PING ]] && LATENCY_RUN="$(ping -c1 "$URL" 2>/dev/null | grep -o 'time=.*' | sed s/'time='//)"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue