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