Sha256: cba009f3ce854d535beb8b6e05edeb2043c026d089545d185e2a3f30da20d217

Contents?: true

Size: 670 Bytes

Versions: 22

Compression:

Stored size: 670 Bytes

Contents

#!/bin/bash

# Retries a command on failure.
# $1 - the max number of attempts
# $2... - the command to run
retry() {
    local -r -i max_attempts="$1"; shift
    local -r cmd="$@"
    local -i attempt_num=1
    local -i cmd_exit_code=0
    until $cmd
    do
        cmd_exit_code=$?
        if (( attempt_num == max_attempts ))
        then
            echo "Attempt $attempt_num failed with code $cmd_exit_code and there are no more attempts left!"
            exit $cmd_exit_code
        else
            echo "Attempt $attempt_num failed with code $cmd_exit_code! Trying again in $attempt_num seconds..."
            sleep $(( attempt_num++ ))
        fi
    done
}

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
soar_authentication_token-7.1.1 retry.sh
soar_authentication_token-7.1.0 retry.sh
soar_authentication_token-7.0.1 retry.sh
soar_authentication_token-7.0.0 retry.sh
soar_authentication_token-6.1.1 retry.sh
soar_authentication_token-6.1.0 retry.sh
soar_authentication_token-6.0.9 retry.sh
soar_json_auditing_format-0.0.2 retry.sh
soar_json_auditing_format-0.0.1 retry.sh
soar_authentication_token-6.0.8 retry.sh
soar_authentication_token-6.0.7 retry.sh
soar_authentication_token-6.0.5 retry.sh
soar_authentication_token-6.0.4 retry.sh
soar_authentication_token-6.0.3 retry.sh
soar_authentication_token-6.0.2 retry.sh
soar_authentication_token-6.0.1 retry.sh
soar_authentication_token-6.0.0 retry.sh
soar_authentication_token-5.0.3 retry.sh
soar_authentication_token-5.0.2 retry.sh
soar_authentication_token-5.0.1 retry.sh