#!/bin/bash # retry.sh — 5 attempts, 120s between, for transport failures only. # usage: retry.sh [args...] set -u n=0 max=5 while [ "$n" -lt "$max" ]; do n=$((n+1)) echo "[retry] attempt $n/$max: $*" >&2 if "$@"; then echo "[retry] success on attempt $n" >&2 exit 0 fi if [ "$n" -lt "$max" ]; then sleep 120 fi done echo "[retry] failed after $max attempts" >&2 exit 1