Created
August 22, 2014 09:00
-
-
Save cbrunnkvist/a3ce5bbea7798a127bc3 to your computer and use it in GitHub Desktop.
Retry command line util exit with success
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 | |
function retry() | |
{ | |
local n=0 | |
local try=$1 | |
local cmd="${@: 2}" | |
[[ $# -le 1 ]] && { | |
echo "Usage $0 <retry_number> <Command>"; } | |
until [[ $n -ge $try ]] | |
do | |
$cmd && break || { | |
echo "Command Fail.." | |
((n++)) | |
echo "retry $n ::" | |
sleep 1; | |
} | |
done | |
} | |
retry $* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment