Skip to content

Instantly share code, notes, and snippets.

@shiroyasha
Last active October 10, 2017 08:33
Show Gist options
  • Save shiroyasha/024ec9fe74a64533bc63f9287c2d97b0 to your computer and use it in GitHub Desktop.
Save shiroyasha/024ec9fe74a64533bc63f9287c2d97b0 to your computer and use it in GitHub Desktop.
function retry {
local n=1
local max=5
local delay=15
while true; do
"$@" && break || {
if [[ $n -lt $max ]]; then
((n++))
echo "Command failed. Attempt $n/$max:"
sleep $delay;
else
echo "The command has failed after $n attempts."
false
fi
}
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment