Skip to content

Commit aa994d5

Browse files
committed
MAINT: Add pure Bourne shell retry_cmd.sh
1 parent ab3ea2d commit aa994d5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tools/retry_cmd.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
#
3+
# retry_cmd.sh [-n NLOOPS] [-s SLEEP] CMD
4+
#
5+
# Retry command until success or pre-specified number of failures
6+
#
7+
# 2018 Chris Markiewicz
8+
# Released into public domain
9+
10+
NLOOPS=3
11+
TOSLEEP=5
12+
13+
while true; do
14+
case "$1" in
15+
-n ) NLOOPS="$2"; shift 2 ;;
16+
-s ) TOSLEEP="$2"; shift 2 ;;
17+
-- ) shift; break ;;
18+
* ) break ;;
19+
esac
20+
done
21+
22+
RET=0
23+
for i in `seq $NLOOPS`; do
24+
sh -c "$@"
25+
RET="$?"
26+
if [ "$RET" -eq 0 ]; then break; fi
27+
if [ "$i" -ne "$NLOOPS" ]; then sleep $TOSLEEP; fi
28+
done
29+
30+
exit $RET

0 commit comments

Comments
 (0)