commit d666b686561a843e9da98dc3d99a06283d2da9dd parent 37098e89dd90eea13a3cbb3fd6129fbf67409d55 Author: Antoine Amarilli <a3nm@a3nm.net> Date: Thu, 18 Jan 2018 17:01:31 +0100 retry Diffstat:
retry | | | 31 | +++++++++++++++++++++++++++++++ |
1 file changed, 31 insertions(+), 0 deletions(-)
diff --git a/retry b/retry @@ -0,0 +1,31 @@ +#!/bin/bash + +# retry command $NTIMES times until it succeeds +# show stderr and stdout from the attempt that succeeded, or the last attempt + +NTIMES="$1" +STATUS=0 +ERROUT=$(mktemp) +STAOUT=$(mktemp) + +shift + +for a in `seq $NTIMES` +do + if [ $a -gt 1 ] + then + sleep 1 + fi + "$@" 2>$ERROUT >$STAOUT + STATUS="$?" + if [ $STATUS -eq 0 ] + then + break + fi +done + +cat "$STAOUT" +cat "$ERROUT" >&2 +rm -f "$ERROUT" "$STAOUT" +exit "$STATUS" +