Retry 10 times. Sleep 5 seconds when retry.
Linux/Mac
./retry10.sh <your_command>Windows (Powershell)
./retry10.ps1 <your_command>| param( | |
| [Parameter(Mandatory = $true, ValueFromRemainingArguments = $true)] | |
| [string[]]$Command | |
| ) | |
| for ($i = 1; $i -le 10; $i++) { | |
| Write-Host "Trying $i..." | |
| & $Command[0] $Command[1..($Command.Length - 1)] | |
| if ($LASTEXITCODE -eq 0) { | |
| break | |
| } | |
| Write-Host "Sleep 5 sec..." | |
| Start-Sleep -Seconds 5 | |
| } |
| # retry10.sh | |
| # Retry command 10 times if fail | |
| # Usage: ./retry10.sh <your_command> | |
| for i in {1..10}; do | |
| echo "Trying $i..." | |
| "$@" && break | |
| [ $i -eq 10 ] && echo "Command failed after 10 attempts" && exit 1 | |
| echo "Sleep 5 sec..." | |
| sleep 5 | |
| done |