#!/bin/bash
function retry()
{
local n=0
local try=$1
local cmd="${@: 2}"
local exit_code=0
[[ $# -le 1 ]] && {
echo "Usage $0
until [[ $n -ge $try ]]
do
$cmd && exit_code=$? && break || {
echo "Command Fail.."
((n++))
echo "retry $n ::"
sleep 1;
}
done
return $exit_code
}
retry $*
Usage:
./scripts/retry.sh 2 pytest