Skip to content

Instantly share code, notes, and snippets.

@alichry
Created September 2, 2020 14:07
Show Gist options
  • Save alichry/1ffc12ee1f5f680f66e68fb28335acb7 to your computer and use it in GitHub Desktop.
Save alichry/1ffc12ee1f5f680f66e68fb28335acb7 to your computer and use it in GitHub Desktop.
#!/bin/sh
default_args="-C - --retry 5"
script_name="$(basename "${0}")"
usage="${script_name} force retries executing curl until it exits successfully.
Passed arguments are passed to curl. By default, we additionally pass these args:
${default_args}
To execute a curl program, you should include the URL and other options,
if necessary. Example:
${script_name} -L -O {URL}"
execute() {
curl ${default_args} "$@"
}
if [ "$#" -lt 1 ]; then
echo "${usage}" 1>&2
exit 1
fi
count=1
ret=1
while [ "${ret}" -eq 1 ];
do
if [ "${count}" -eq 1 ]; then
echo "Executing curl ${default_args}" "$@" 1>&2
else
echo "${count}: Trying again to execute curl" 1>&2
fi
if execute "$@"; then
ret=0
fi
count=$((count + 1))
echo "---------------"
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment