Created
November 16, 2015 18:37
-
-
Save jgraham909/592615563f7c197b462f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FAIL=1 # or some non zero error number you want | |
MAX_TRIES=4 | |
COUNT=0 | |
BACKOFF=1 | |
if [ $# -lt 1 ];then | |
echo "You must provide a command to execute. Commands with arguments must be quoted." | |
exit 1 | |
fi | |
echo "Executing '$1' up to $MAX_TRIES times" | |
while [ $COUNT -lt $MAX_TRIES ]; do | |
($1) | |
if [ $? -eq 0 ];then | |
exit 0 | |
fi | |
let COUNT=COUNT+1 | |
let BACKOFF=BACKOFF*2 | |
echo "Attempt $COUNT failed retrying after $BACKOFF seconds" | |
sleep $BACKOFF | |
done | |
echo "Tried and failed $COUNT times. Giving up." | |
exit $FAIL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment