#!/bin/bash # Retry function with exponential backoff # Usage: source retry.sh && retry retry() { local max_attempts=3 local delay=5 local attempt=1 until "$@"; do if [ "$attempt" -ge "$max_attempts" ]; then echo "Command failed after $max_attempts attempts: $*" return 1 fi echo "Command failed (attempt $attempt/$max_attempts): $*" echo "Retrying in $delay seconds..." sleep "$delay" attempt=$((attempt + 1)) delay=$((delay * 2)) # Exponential backoff done }