Skip to content

Instantly share code, notes, and snippets.

@taxilian
Created August 4, 2021 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taxilian/aa5ee596687bae0888366f295575fce6 to your computer and use it in GitHub Desktop.
Save taxilian/aa5ee596687bae0888366f295575fce6 to your computer and use it in GitHub Desktop.
Tool for testing how often a command succeeds
#!/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