aboutsummaryrefslogtreecommitdiff
path: root/scripts/retry.sh
blob: 82455169adf00a63c04a3e6d1ab2796d5a98f6db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env bash

#Taken from https://gist.github.com/sj26/88e1c6584397bb7c13bd11108a579746

retries=$1
shift

count=0
until "$@"; do
    exit=$?
    count=$(($count + 1))
    if [[ ${count} -lt ${retries} ]]; then
      echo "Retry ${count}/${retries} exited ${exit}, retrying in ${count} seconds..."
      sleep ${count}
    else
      echo "Retry ${count}/${retries} exited ${exit}, no more retries left."
      exit ${exit}
    fi
done