Skip to content

Instantly share code, notes, and snippets.

@luminousmen
Created December 22, 2022 04:24
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 luminousmen/47c70a56d142b18bba58310cdd941705 to your computer and use it in GitHub Desktop.
Save luminousmen/47c70a56d142b18bba58310cdd941705 to your computer and use it in GitHub Desktop.
Bash retry function
function retry {
local retries=3
local count=0
until "$@"; do
exit=$?
wait=$((10 ** $count))
count=$(($count + 1))
if [ $count -lt $retries ]; then
echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
sleep $wait
else
echo "Retry $count/$retries exited $exit, no more retries left."
return $exit
fi
done
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment