We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ab3ea2d commit aa994d5Copy full SHA for aa994d5
tools/retry_cmd.sh
@@ -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
29
30
+exit $RET
0 commit comments