Created
December 22, 2022 04:24
-
-
Save luminousmen/47c70a56d142b18bba58310cdd941705 to your computer and use it in GitHub Desktop.
Bash retry function
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
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