Skip to content

Instantly share code, notes, and snippets.

@fridim
Last active October 22, 2020 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fridim/9fbc20900d4b4569ccaf78f1b6f2b464 to your computer and use it in GitHub Desktop.
Save fridim/9fbc20900d4b4569ccaf78f1b6f2b464 to your computer and use it in GitHub Desktop.
Retry wrapper in Bash
do_cmd_timeout_retry() {
local RETRIES=0
local MAX_RETRIES=10
local TIMEOUT=60
local DELAY=60
while [[ $RETRIES -le $MAX_RETRIES ]]; do
timeout ${TIMEOUT} "$@"
local ret=$?
[[ $ret == 0 ]] && break
echo "command '$@' failed, retrying in $DELAY"
RETRIES=$((RETRIES + 1))
sleep ${DELAY}
done
}
do_cmd_retry_timeout git pull ... # if github temporary down, it'll retry for ~10 min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment