1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/bin/bash attempts=0 max_attempts=60 echo "Waiting for command '$@' to be successful..." while ! eval $@; do attempts=$(($attempts+1)) if [[ $attempts -gt $max_attempts ]]; then echo "command '$@' took too long to be successful" exit 1 fi sleep 1 done