Skip to content

Instantly share code, notes, and snippets.

@cloudnull
Last active August 29, 2015 13:58
Show Gist options
  • Save cloudnull/10437603 to your computer and use it in GitHub Desktop.
Save cloudnull/10437603 to your computer and use it in GitHub Desktop.
BASH Successerator. when running a process that has a high probability of failure use this function as a means to ensure the operation is run multiple times.
# BASH Successerator. when running a process that has a high
# probability of failure use this function as a means to
# ensure the operation is run multiple times.
# Usage:
# successerator knife bootstrap -e ENV -r 'role[one],recipie[two]'
# Used to retry process that may fail due to random issues.
function successerator() {
MAX_RETRIES=${MAX_RETRIES:-5}
RETRY=0
# Set the initial return value to failure
false
while [ $? -ne 0 -a ${RETRY} -lt ${MAX_RETRIES} ];do
RETRY=$((${RETRY}+1))
$@
done
if [ ${RETRY} -eq ${MAX_RETRIES} ];then
echo "Hit maximum number of retries, giving up..."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment