Skip to content

Instantly share code, notes, and snippets.

@cbrunnkvist
Created August 22, 2014 09:00
Show Gist options
  • Save cbrunnkvist/a3ce5bbea7798a127bc3 to your computer and use it in GitHub Desktop.
Save cbrunnkvist/a3ce5bbea7798a127bc3 to your computer and use it in GitHub Desktop.
Retry command line util exit with success
#!/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