| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | cmd=$@ |
| 4 | |
| 5 | function elog() { |
| 6 | message=$1 |
| 7 | printf "%(%Y/%m/%d %H:%M:%S)T | retry.sh $1\n" |
| 8 | } |
| 9 | |
| 10 | declare -i iteration=0 |
| 11 | declare -i max_iterations=9 |
| 12 | for((iteration=1;iteration<=max_iterations;iteration++)); do |
| 13 | elog "iteration: $iteration/$max_iterations, cmd: $cmd" |
| 14 | if $cmd; then |
| 15 | exit 0 |
| 16 | fi |
| 17 | elog "command failed, retrying ..."; |
| 18 | sleep 1; |
| 19 | done; |
| 20 | |
| 21 | elog "failed doing $max_iterations iterations of command: $cmd" |
| 22 | exit 1 |
| 23 |