Created
August 4, 2021 16:33
-
-
Save taxilian/aa5ee596687bae0888366f295575fce6 to your computer and use it in GitHub Desktop.
Tool for testing how often a command succeeds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CMD="$@" | |
declare -i COUNT | |
declare -i SUCCESS | |
SUCCESS=0 | |
COUNT=0 | |
for i in {1..100}; do | |
echo -n "${i}: Running command '$@'... " | |
eval "$@" > /dev/null 2>&1 | |
RES=$? | |
if [ $RES -eq 0 ]; then | |
SUCCESS=$(echo $SUCCESS + 1 | bc) | |
echo "Success" | |
else | |
echo "Failed" | |
fi | |
COUNT=$(echo $COUNT + 1 | bc) | |
done | |
AVG=$(echo $SUCCESS $COUNT | awk '{printf "%.1f", $1 / $2 * 100}') | |
echo "Success rate: ${AVG} ($SUCCESS times out of $COUNT)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment