aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/try19
-rw-r--r--man/man1/try.19
2 files changed, 20 insertions, 8 deletions
diff --git a/bin/try b/bin/try
index cdf98d01..ce66a722 100755
--- a/bin/try
+++ b/bin/try
@@ -6,8 +6,9 @@
# failed. Designed for running from systems like cron(8) where blips and
# short-term failures can be ignored.
#
-# -h gives help, -n sets the number of attempts (defaults to 3), -v gives you
-# diagnostics on stdout.
+# -h gives help, -v gives you diagnostics on stdout, -i sets an optional number
+# of seconds between each attempt, -n sets the number of attempts (defaults to
+# 3).
#
# Author: Tom Ryder <tom@sanctum.geek.nz>
# Copyright: 2016
@@ -17,7 +18,7 @@ self=try
# Print usage information
usage() {
- printf '%s: usage: %s [-hv] [-n ATTEMPTS] [--] COMMAND...\n' \
+ printf '%s: usage: %s [-hv] [-i INTERVAL] [-n ATTEMPTS] [--] COMMAND...\n' \
"$self" "$self"
}
@@ -25,12 +26,16 @@ usage() {
declare -i verbose
verbose=0
+# Number of seconds to wait between instances
+declare -i interval
+interval=0
+
# Number of attempts
declare -i attc
attc=3
# Process options
-while getopts 'hvn:' opt ; do
+while getopts 'hvi:n:' opt ; do
case $opt in
# -h: Print help
@@ -44,6 +49,11 @@ while getopts 'hvn:' opt ; do
verbose=1
;;
+ # -i: Set the number of seconds between attempts
+ i)
+ interval=$OPTARG
+ ;;
+
# -n: Set the number of attempts
n)
attc=$OPTARG
@@ -89,6 +99,7 @@ for (( atti = 1 ; atti <= attc ; atti++ )) ; do
ret=$?
((verbose)) && printf '%s: Failure!\n' \
"$self"
+ sleep "$interval"
fi
done
diff --git a/man/man1/try.1 b/man/man1/try.1
index 482872fb..380c0a29 100644
--- a/man/man1/try.1
+++ b/man/man1/try.1
@@ -3,14 +3,15 @@
.B try
\- attempt a command up to a certain number of times until it succeeds
.SH USAGE
-.B try [-hv] [-n ATTEMPTS] [--] COMMAND...
+.B try [-hv] [-i INTERVAL] [-n ATTEMPTS] [--] COMMAND...
.SH DESCRIPTION
Runs the given command up to a fixed number of times until it exits zero. If
all attempts fail, writes buffered error output from all attempts to stderr.
.P
-Option -h gives help, option -v turns on verbose output, option -n specifies
-the number of attempts; defaults to 3. Options may be terminated with --. The
-remaining arguments are the command to run.
+Option -h gives help, option -v turns on verbose output, option -i specifies an
+optional number of seconds between attempts, and option -n specifies the number
+of attempts; defaults to 3. Options may be terminated with --. The remaining
+arguments are the command to run.
.P
$ try getmails
$ try -v -n3 maybe