Last active
October 15, 2021 11:24
-
-
Save alichry/feee07868cbccf80856ae291427e3bc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
script_name="$(basename "${0}")" | |
usage="${script_name}: force retries executing a custom command until it exits successfully. | |
Usage: | |
${script_name} COMMAND ARG1 ARG2 ... | |
Example: | |
${script_name} curl -C - --retry 5 -L -O {URL}" | |
if [ "$#" -lt 1 ]; then | |
echo "${usage}" 1>&2 | |
exit 1 | |
fi | |
count=1 | |
execute() { | |
local ret | |
echo "Executing command: " "$@" 1>&2 | |
if "$@"; ret="$?"; [ "$ret" -ne 0 ]; then | |
echo "Command failed with exit code $ret" | |
return "$ret" | |
fi | |
return 0 | |
} | |
#while echo "Executing command:" "$@" 1>&2 && ! "$@" | |
while ! execute "$@" | |
do | |
sleep 1 | |
echo "------------------------\n" | |
echo "Retrying... (attempt: ${count})" | |
count=$((count + 1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: