Skip to content
Snippets Groups Projects
Commit 174dc54c authored by nimrod's avatar nimrod
Browse files

New retry script.

Retry commands.
parent 974c60c0
No related branches found
No related tags found
No related merge requests found
#!/bin/sh
set -eu
alias red="printf '\e[1;91m%s\e[0m\n'"
usage () {
echo "$(basename "$0"): RETRIES COMMAND [ARG1 [ARG2 [...]]]"
exit 1
}
if [ "$#" -lt 2 ] || [ "$1" -lt 1 ]
then
usage
fi
retries="$1"
shift
for _ in $(seq "$retries")
do
"$@" || status="$?"
if [ "${status:-0}" -eq 0 ]
then
break
elif [ "$_" -eq "$retries" ]
then
red "${1} failed too many times." >&2
exit "$status"
else
case "$_" in
1) duration=5;;
2) duration=15;;
3) duration=30;;
4) duration=60;;
5) duration=120;;
*) duration=300;;
esac
red "${1} failed, going to retry in ${duration} seconds." >&2
sleep "$duration"
fi
done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment