Skip to content

Instantly share code, notes, and snippets.

@ghostwriter
Created September 22, 2023 17:25
Show Gist options
  • Save ghostwriter/6d961aa42ff7e2bc854290021932bf74 to your computer and use it in GitHub Desktop.
Save ghostwriter/6d961aa42ff7e2bc854290021932bf74 to your computer and use it in GitHub Desktop.
num_args=$#
max_runs=$1
sleep=$2
cmd=$3
shift 3
args=("$@")
runs=0
[[ $num_args -le 2 ]] && echo "Usage retry.sh <sleep> <retry_times> <command>" && exit 0;
until [[ $runs -ge $max_runs ]]
do
if $cmd "${args[@]}"; then
break;
else
echo "Failed"
((runs++))
echo "retry $runs ::"
sleep "$sleep";
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment