Skip to content

Commit a38f473

Browse files
authored
fix remaining shellcheck findings
1 parent c94cd19 commit a38f473

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

yabs.sh

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# performance via fio. The script is designed to not require any dependencies
1313
# - either compiled or installed - nor admin privileges to run.
1414

15-
YABS_VERSION="v2024-12-17"
15+
YABS_VERSION="v2024-12-20"
1616

1717
echo -e '# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #'
1818
echo -e '# Yet-Another-Bench-Script #'
@@ -436,11 +436,11 @@ function format_iops {
436436
# divide the raw result by 1k
437437
RESULT=$(awk -v a="$RESULT" 'BEGIN { print a / 1000 }')
438438
# shorten the formatted result to one decimal place (i.e. x.x)
439-
RESULT=$(echo $RESULT | awk -F. '{ printf "%0.1f",$1"."substr($2,1,1) }')
439+
RESULT=$(echo "$RESULT" | awk -F. '{ printf "%0.1f",$1"."substr($2,1,1) }')
440440
RESULT="$RESULT"k
441441
fi
442442

443-
echo $RESULT
443+
echo "$RESULT"
444444
}
445445

446446
# disk_test
@@ -541,7 +541,7 @@ elif [ -z "$SKIP_FIO" ]; then
541541

542542
for pathls in $(df -Th | awk '{print $7}' | tail -n +2)
543543
do
544-
if [[ "${PWD##$pathls}" != "$PWD" ]]; then
544+
if [[ "${PWD##"$pathls"}" != "$PWD" ]]; then
545545
poss+=("$pathls")
546546
fi
547547
done
@@ -564,7 +564,7 @@ elif [ -z "$SKIP_FIO" ]; then
564564
size_b='G'
565565
fi
566566

567-
if [[ $(df -Th | grep -w $long) == *"zfs"* ]];then
567+
if [[ $(df -Th | grep -w "$long") == *"zfs"* ]];then
568568

569569
if [[ $size_b == 'G' ]]; then
570570
if ((free_space < mul_spa)); then
@@ -627,13 +627,13 @@ elif [ -z "$SKIP_FIO" ]; then
627627
dd_test
628628

629629
# format the speed averages by converting to GB/s if > 1000 MB/s
630-
if [ $(echo $DISK_WRITE_TEST_AVG | cut -d "." -f 1) -ge 1000 ]; then
630+
if [ "$(echo "$DISK_WRITE_TEST_AVG" | cut -d "." -f 1)" -ge 1000 ]; then
631631
DISK_WRITE_TEST_AVG=$(awk -v a="$DISK_WRITE_TEST_AVG" 'BEGIN { print a / 1000 }')
632632
DISK_WRITE_TEST_UNIT="GB/s"
633633
else
634634
DISK_WRITE_TEST_UNIT="MB/s"
635635
fi
636-
if [ $(echo $DISK_READ_TEST_AVG | cut -d "." -f 1) -ge 1000 ]; then
636+
if [ "$(echo "$DISK_READ_TEST_AVG" | cut -d "." -f 1)" -ge 1000 ]; then
637637
DISK_READ_TEST_AVG=$(awk -v a="$DISK_READ_TEST_AVG" 'BEGIN { print a / 1000 }')
638638
DISK_READ_TEST_UNIT="GB/s"
639639
else
@@ -645,21 +645,21 @@ elif [ -z "$SKIP_FIO" ]; then
645645
echo -e "dd Sequential Disk Speed Tests:"
646646
echo -e "---------------------------------"
647647
printf "%-6s | %-6s %-4s | %-6s %-4s | %-6s %-4s | %-6s %-4s\n" "" "Test 1" "" "Test 2" "" "Test 3" "" "Avg" ""
648-
printf "%-6s | %-6s %-4s | %-6s %-4s | %-6s %-4s | %-6s %-4s\n"
648+
printf "%-6s | %-6s %-4s | %-6s %-4s | %-6s %-4s | %-6s %-4s\n" "" "" "" "" "" "" "" "" ""
649649
printf "%-6s | %-11s | %-11s | %-11s | %-6.2f %-4s\n" "Write" "${DISK_WRITE_TEST_RES[0]}" "${DISK_WRITE_TEST_RES[1]}" "${DISK_WRITE_TEST_RES[2]}" "${DISK_WRITE_TEST_AVG}" "${DISK_WRITE_TEST_UNIT}"
650650
printf "%-6s | %-11s | %-11s | %-11s | %-6.2f %-4s\n" "Read" "${DISK_READ_TEST_RES[0]}" "${DISK_READ_TEST_RES[1]}" "${DISK_READ_TEST_RES[2]}" "${DISK_READ_TEST_AVG}" "${DISK_READ_TEST_UNIT}"
651651
else # fio tests completed successfully, print results
652652
CURRENT_PARTITION=$(df -P . 2>/dev/null | tail -1 | cut -d' ' -f 1)
653653
[[ -n $JSON ]] && JSON_RESULT+=',"partition":"'$CURRENT_PARTITION'","fio":['
654-
DISK_RESULTS_NUM=$(expr ${#DISK_RESULTS[@]} / 6)
654+
DISK_RESULTS_NUM=$((${#DISK_RESULTS[@]} / 6))
655655
DISK_COUNT=0
656656

657657
# print disk speed test results
658658
echo -e "fio Disk Speed Tests (Mixed R/W 50/50) (Partition $CURRENT_PARTITION):"
659659
echo -e "---------------------------------"
660660

661-
while [ $DISK_COUNT -lt $DISK_RESULTS_NUM ] ; do
662-
if [ $DISK_COUNT -gt 0 ]; then printf "%-10s | %-20s | %-20s\n"; fi
661+
while [[ $DISK_COUNT -lt $DISK_RESULTS_NUM ]] ; do
662+
if [[ $DISK_COUNT -gt 0 ]]; then printf "%-10s | %-20s | %-20s\n" "" "" ""; fi
663663
printf "%-10s | %-11s %8s | %-11s %8s\n" "Block Size" "${BLOCK_SIZES[DISK_COUNT]}" "(IOPS)" "${BLOCK_SIZES[DISK_COUNT+1]}" "(IOPS)"
664664
printf "%-10s | %-11s %8s | %-11s %8s\n" " ------" "---" "---- " "----" "---- "
665665
printf "%-10s | %-11s %8s | %-11s %8s\n" "Read" "${DISK_RESULTS[DISK_COUNT*6+1]}" "(${DISK_RESULTS[DISK_COUNT*6+4]})" "${DISK_RESULTS[(DISK_COUNT+1)*6+1]}" "(${DISK_RESULTS[(DISK_COUNT+1)*6+4]})"
@@ -673,7 +673,7 @@ elif [ -z "$SKIP_FIO" ]; then
673673
JSON_RESULT+=',"speed_w":'${DISK_RESULTS_RAW[(DISK_COUNT+1)*6+2]}',"iops_w":'${DISK_RESULTS_RAW[(DISK_COUNT+1)*6+5]}',"speed_rw":'${DISK_RESULTS_RAW[(DISK_COUNT+1)*6]}
674674
JSON_RESULT+=',"iops_rw":'${DISK_RESULTS_RAW[(DISK_COUNT+1)*6+3]}',"speed_units":"KBps"},'
675675
fi
676-
DISK_COUNT=$(expr $DISK_COUNT + 2)
676+
DISK_COUNT=$(($DISK_COUNT + 2))
677677
done
678678
[[ -n $JSON ]] && JSON_RESULT=${JSON_RESULT::${#JSON_RESULT}-1} && JSON_RESULT+=']'
679679
fi
@@ -701,20 +701,20 @@ function iperf_test {
701701
do
702702
echo -en "Performing $MODE iperf3 send test to $HOST (Attempt #$I of 3)..."
703703
# select a random iperf port from the range provided
704-
PORT=$(shuf -i $PORTS -n 1)
704+
PORT=$(shuf -i "$PORTS" -n 1)
705705
# run the iperf test sending data from the host to the iperf server; includes
706706
# a timeout of 15s in case the iperf server is not responding; uses 8 parallel
707707
# threads for the network test
708-
IPERF_RUN_SEND="$(timeout 15 $IPERF_CMD $FLAGS -c "$URL" -p $PORT -P 8 2> /dev/null)"
708+
IPERF_RUN_SEND="$(timeout 15 "$IPERF_CMD" "$FLAGS" -c "$URL" -p "$PORT" -P 8 2> /dev/null)"
709709
# check if iperf exited cleanly and did not return an error
710710
if [[ "$IPERF_RUN_SEND" == *"receiver"* && "$IPERF_RUN_SEND" != *"error"* ]]; then
711711
# test did not result in an error, parse speed result
712712
SPEED=$(echo "${IPERF_RUN_SEND}" | grep SUM | grep receiver | awk '{ print $6 }')
713713
# if speed result is blank or bad (0.00), rerun, otherwise set counter to exit loop
714-
[[ -z $SPEED || "$SPEED" == "0.00" ]] && I=$(( $I + 1 )) || I=11
714+
[[ -z $SPEED || "$SPEED" == "0.00" ]] && I=$(( I + 1 )) || I=11
715715
else
716716
# if iperf server is not responding, set counter to exit, otherwise increment, sleep, and rerun
717-
[[ "$IPERF_RUN_SEND" == *"unable to connect"* ]] && I=11 || I=$(( $I + 1 )) && sleep 2
717+
[[ "$IPERF_RUN_SEND" == *"unable to connect"* ]] && I=11 || I=$(( I + 1 )) && sleep 2
718718
fi
719719
echo -en "\r\033[0K"
720720
done
@@ -729,32 +729,32 @@ function iperf_test {
729729
do
730730
echo -n "Performing $MODE iperf3 recv test from $HOST (Attempt #$J of 3)..."
731731
# select a random iperf port from the range provided
732-
PORT=$(shuf -i $PORTS -n 1)
732+
PORT=$(shuf -i "$PORTS" -n 1)
733733
# run the iperf test receiving data from the iperf server to the host; includes
734734
# a timeout of 15s in case the iperf server is not responding; uses 8 parallel
735735
# threads for the network test
736-
IPERF_RUN_RECV="$(timeout 15 $IPERF_CMD $FLAGS -c "$URL" -p $PORT -P 8 -R 2> /dev/null)"
736+
IPERF_RUN_RECV="$(timeout 15 "$IPERF_CMD" "$FLAGS" -c "$URL" -p "$PORT" -P 8 -R 2> /dev/null)"
737737
# check if iperf exited cleanly and did not return an error
738738
if [[ "$IPERF_RUN_RECV" == *"receiver"* && "$IPERF_RUN_RECV" != *"error"* ]]; then
739739
# test did not result in an error, parse speed result
740740
SPEED=$(echo "${IPERF_RUN_RECV}" | grep SUM | grep receiver | awk '{ print $6 }')
741741
# if speed result is blank or bad (0.00), rerun, otherwise set counter to exit loop
742-
[[ -z $SPEED || "$SPEED" == "0.00" ]] && J=$(( $J + 1 )) || J=11
742+
[[ -z $SPEED || "$SPEED" == "0.00" ]] && J=$(( J + 1 )) || J=11
743743
else
744744
# if iperf server is not responding, set counter to exit, otherwise increment, sleep, and rerun
745-
[[ "$IPERF_RUN_RECV" == *"unable to connect"* ]] && J=11 || J=$(( $J + 1 )) && sleep 2
745+
[[ "$IPERF_RUN_RECV" == *"unable to connect"* ]] && J=11 || J=$(( J + 1 )) && sleep 2
746746
fi
747747
echo -en "\r\033[0K"
748748
done
749749

750750
# Run a latency test via ping -c1 command -> will return "xx.x ms"
751-
[[ -n $LOCAL_PING ]] && LATENCY_RUN="$(ping -c1 $URL 2>/dev/null | grep -o 'time=.*' | sed s/'time='//)"
751+
[[ -n $LOCAL_PING ]] && LATENCY_RUN="$(ping -c1 "$URL" 2>/dev/null | grep -o 'time=.*' | sed s/'time='//)"
752752
[[ -z $LATENCY_RUN ]] && LATENCY_RUN="--"
753753

754754
# parse the resulting send and receive speed results
755755
IPERF_SENDRESULT="$(echo "${IPERF_RUN_SEND}" | grep SUM | grep receiver)"
756756
IPERF_RECVRESULT="$(echo "${IPERF_RUN_RECV}" | grep SUM | grep receiver)"
757-
LATENCY_RESULT="$(echo "${LATENCY_RUN}")"
757+
LATENCY_RESULT="${LATENCY_RUN}"
758758
}
759759

760760
# launch_iperf
@@ -780,11 +780,11 @@ function launch_iperf {
780780
# call the iperf_test function passing the required parameters
781781
iperf_test "${IPERF_LOCS[i*5]}" "${IPERF_LOCS[i*5+1]}" "${IPERF_LOCS[i*5+2]}" "$IPERF_FLAGS"
782782
# parse the send and receive speed results
783-
IPERF_SENDRESULT_VAL=$(echo $IPERF_SENDRESULT | awk '{ print $6 }')
784-
IPERF_SENDRESULT_UNIT=$(echo $IPERF_SENDRESULT | awk '{ print $7 }')
785-
IPERF_RECVRESULT_VAL=$(echo $IPERF_RECVRESULT | awk '{ print $6 }')
786-
IPERF_RECVRESULT_UNIT=$(echo $IPERF_RECVRESULT | awk '{ print $7 }')
787-
LATENCY_VAL=$(echo $LATENCY_RESULT)
783+
IPERF_SENDRESULT_VAL=$(echo "$IPERF_SENDRESULT" | awk '{ print $6 }')
784+
IPERF_SENDRESULT_UNIT=$(echo "$IPERF_SENDRESULT" | awk '{ print $7 }')
785+
IPERF_RECVRESULT_VAL=$(echo "$IPERF_RECVRESULT" | awk '{ print $6 }')
786+
IPERF_RECVRESULT_UNIT=$(echo "$IPERF_RECVRESULT" | awk '{ print $7 }')
787+
LATENCY_VAL="${LATENCY_RESULT}"
788788
# if the results are blank, then the server is "busy" and being overutilized
789789
[[ -z $IPERF_SENDRESULT_VAL || "$IPERF_SENDRESULT_VAL" == *"0.00"* ]] && IPERF_SENDRESULT_VAL="busy" && IPERF_SENDRESULT_UNIT=""
790790
[[ -z $IPERF_RECVRESULT_VAL || "$IPERF_RECVRESULT_VAL" == *"0.00"* ]] && IPERF_RECVRESULT_VAL="busy" && IPERF_RECVRESULT_UNIT=""
@@ -924,7 +924,7 @@ function launch_geekbench {
924924
fi
925925

926926
# unlock if license file detected
927-
test -f "geekbench.license" && "$GEEKBENCH_PATH/$GB_CMD" --unlock $(cat geekbench.license) > /dev/null 2>&1
927+
test -f "geekbench.license" && "$GEEKBENCH_PATH/$GB_CMD" --unlock "$(cat geekbench.license)" > /dev/null 2>&1
928928

929929
# run the Geekbench test and grep the test results URL given at the end of the test
930930
GEEKBENCH_TEST=$("$GEEKBENCH_PATH/$GB_CMD" --upload 2>/dev/null | grep "https://browser")
@@ -947,24 +947,24 @@ function launch_geekbench {
947947
fi
948948
else
949949
# if the Geekbench test succeeded, parse the test results URL
950-
GEEKBENCH_URL=$(echo -e $GEEKBENCH_TEST | head -1)
951-
GEEKBENCH_URL_CLAIM=$(echo $GEEKBENCH_URL | awk '{ print $2 }')
952-
GEEKBENCH_URL=$(echo $GEEKBENCH_URL | awk '{ print $1 }')
950+
GEEKBENCH_URL=$(echo -e "$GEEKBENCH_TEST" | head -1)
951+
GEEKBENCH_URL_CLAIM=$(echo "$GEEKBENCH_URL" | awk '{ print $2 }')
952+
GEEKBENCH_URL=$(echo "$GEEKBENCH_URL" | awk '{ print $1 }')
953953
# sleep a bit to wait for results to be made available on the geekbench website
954954
sleep 10
955955
# parse the public results page for the single and multi core geekbench scores
956-
[[ $VERSION == *4* ]] && GEEKBENCH_SCORES=$($DL_CMD $GEEKBENCH_URL | grep "span class='score'") || \
957-
GEEKBENCH_SCORES=$($DL_CMD $GEEKBENCH_URL | grep "div class='score'")
956+
[[ $VERSION == *4* ]] && GEEKBENCH_SCORES=$($DL_CMD "$GEEKBENCH_URL" | grep "span class='score'") || \
957+
GEEKBENCH_SCORES=$($DL_CMD "$GEEKBENCH_URL" | grep "div class='score'")
958958

959-
GEEKBENCH_SCORES_SINGLE=$(echo $GEEKBENCH_SCORES | awk -v FS="(>|<)" '{ print $3 }')
960-
GEEKBENCH_SCORES_MULTI=$(echo $GEEKBENCH_SCORES | awk -v FS="(>|<)" '{ print $7 }')
959+
GEEKBENCH_SCORES_SINGLE=$(echo "$GEEKBENCH_SCORES" | awk -v FS="(>|<)" '{ print $3 }')
960+
GEEKBENCH_SCORES_MULTI=$(echo "$GEEKBENCH_SCORES" | awk -v FS="(>|<)" '{ print $7 }')
961961

962962
# print the Geekbench results
963963
echo -en "\r\033[0K"
964964
echo -e "Geekbench $VERSION Benchmark Test:"
965965
echo -e "---------------------------------"
966966
printf "%-15s | %-30s\n" "Test" "Value"
967-
printf "%-15s | %-30s\n"
967+
printf "%-15s | %-30s\n" "" ""
968968
printf "%-15s | %-30s\n" "Single Core" "$GEEKBENCH_SCORES_SINGLE"
969969
printf "%-15s | %-30s\n" "Multi Core" "$GEEKBENCH_SCORES_MULTI"
970970
printf "%-15s | %-30s\n" "Full Test" "$GEEKBENCH_URL"
@@ -982,7 +982,7 @@ function launch_geekbench {
982982

983983
# if the skip geekbench flag was set, skip the system performance test, otherwise test system performance
984984
if [ -z "$SKIP_GEEKBENCH" ]; then
985-
[[ -n $JSON ]] && JSON_RESULT+=',"geekbench":['
985+
[[ -n $JSON ]] && JSON_RESULT+=(",\"geekbench\":[")
986986
if [[ $GEEKBENCH_4 == *True* ]]; then
987987
launch_geekbench 4
988988
fi
@@ -994,7 +994,7 @@ if [ -z "$SKIP_GEEKBENCH" ]; then
994994
if [[ $GEEKBENCH_6 == *True* ]]; then
995995
launch_geekbench 6
996996
fi
997-
[[ -n $JSON ]] && [[ $(echo -n $JSON_RESULT | tail -c 1) == ',' ]] && JSON_RESULT=${JSON_RESULT::${#JSON_RESULT}-1}
997+
[[ -n $JSON ]] && [[ "${JSON_RESULT: -1}" == ',' ]] && JSON_RESULT=$(echo "$JSON_RESULT" | sed 's/,$//')
998998
[[ -n $JSON ]] && JSON_RESULT+=']'
999999
fi
10001000

@@ -1013,25 +1013,25 @@ function calculate_time_taken() {
10131013
end_time=$1
10141014
start_time=$2
10151015

1016-
time_taken=$(( ${end_time} - ${start_time} ))
1016+
time_taken=$(( end_time - start_time ))
10171017
if [ ${time_taken} -gt 60 ]; then
1018-
min=$(expr $time_taken / 60)
1019-
sec=$(expr $time_taken % 60)
1018+
min=$(( time_taken / 60 ))
1019+
sec=$(( time_taken % 60 ))
10201020
echo "YABS completed in ${min} min ${sec} sec"
10211021
else
10221022
echo "YABS completed in ${time_taken} sec"
10231023
fi
10241024
[[ -n $JSON ]] && JSON_RESULT+=',"runtime":{"start":'$start_time',"end":'$end_time',"elapsed":'$time_taken'}'
10251025
}
10261026

1027-
calculate_time_taken $YABS_END_TIME $YABS_START_TIME
1027+
calculate_time_taken "$YABS_END_TIME" "$YABS_START_TIME"
10281028

10291029
if [[ -n $JSON ]]; then
10301030
JSON_RESULT+='}'
10311031

10321032
# write json results to file
10331033
if [[ $JSON = *w* ]]; then
1034-
echo $JSON_RESULT > "$JSON_FILE"
1034+
echo "$JSON_RESULT" > "$JSON_FILE"
10351035
fi
10361036

10371037
# send json results
@@ -1040,17 +1040,17 @@ if [[ -n $JSON ]]; then
10401040
for JSON_SITE in "${JSON_SITES[@]}"
10411041
do
10421042
if [[ -n $LOCAL_CURL ]]; then
1043-
curl -s -H "Content-Type:application/json" -X POST --data ''"$JSON_RESULT"'' $JSON_SITE
1043+
curl -s -H "Content-Type:application/json" -X POST --data ''"$JSON_RESULT"'' "$JSON_SITE"
10441044
else
1045-
wget -qO- --post-data=''"$JSON_RESULT"'' --header='Content-Type:application/json' $JSON_SITE
1045+
wget -qO- --post-data=''"$JSON_RESULT"'' --header='Content-Type:application/json' "$JSON_SITE"
10461046
fi
10471047
done
10481048
fi
10491049

10501050
# print json result to screen
10511051
if [[ $JSON = *j* ]]; then
10521052
echo -e
1053-
echo $JSON_RESULT
1053+
echo "$JSON_RESULT"
10541054
fi
10551055
fi
10561056

0 commit comments

Comments
 (0)