cheeky-retries.sh 400 B

12345678910111213141516171819
  1. #!/usr/bin/env bash
  2. set -Eeuo pipefail
  3. # intended to be symlinked as "run.sh" next to "real-run.sh" such that we give "real-run.sh" a couple tries to succeed before we give up
  4. dir="$(dirname "$BASH_SOURCE")"
  5. tries=3
  6. while [ "$tries" -gt 0 ]; do
  7. (( tries-- )) || :
  8. if "$dir/real-run.sh" "$@"; then
  9. exit 0
  10. fi
  11. if [ "$tries" -gt 0 ]; then
  12. echo >&2 'warning: failed, retrying'
  13. fi
  14. done
  15. exit 1