Skip to content

Instantly share code, notes, and snippets.

@unakatsuo
Created June 15, 2011 09:05
Show Gist options
  • Select an option

  • Save unakatsuo/1026755 to your computer and use it in GitHub Desktop.

Select an option

Save unakatsuo/1026755 to your computer and use it in GitHub Desktop.
bash retry function
function retry {
local retry_max=$1
shift
local count=$retry_max
while [[ $count -gt 0 ]]; do
$* && break
count=$(($count - 1))
sleep 1
done
[[ $count -eq 0 ]] && {
echo "Retry failed [$retry_max]: ${*}" >&2
exit 1;
}
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment