Skip to content

Instantly share code, notes, and snippets.

@imvaskii
Created October 2, 2018 09:31
Show Gist options
  • Save imvaskii/d86f08a59bdc862ca78aaf275eff2736 to your computer and use it in GitHub Desktop.
Save imvaskii/d86f08a59bdc862ca78aaf275eff2736 to your computer and use it in GitHub Desktop.
A bash function to wait and retry command.
# Public: Execute commands until 5 consecutive time waiting 15 seconds in each retries.
#
# Takes a single argument.
#
# $@ - Passed argument to be executed.
#
# Examples
#
# retry rake spec
#
# Returns the exit code of the last command executed in debug mode or 0
function wait_n_retry() {
retry_count=0
until [ $retry_count -ge 5 ]; do
return $@ && break
retry_count=$(($retry_count + 1))
echo "Retrying command \"$@\" : count -$retry_count \n"
sleep 10
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment