retry-cli

A utility for retrying failed CLI commands on Unix-like systems.

Download v1.0.0

Options

retry [OPTIONS] <COMMAND>...

-a, --attempts <ATTEMPTS>
The total number of attempts [default: 5]
-d, --delay <DELAY>
How long to wait before each retry [default: 1s]
-m, --delay-multiplier <DELAY_MULTIPLIER>
Multiply the delay after each failed attempt [default: 1]
-q, --quiet
Suppress output when the wrapped command fails
-h, --help  /  -V, --version

Examples

# Default: 1s delay, 5 attempts
$ retry /path/to/mission-critical-script.sh

# No delay, 3 attempts
$ retry --delay 0s --attempts 3 ssh user@some.host some-remote-task

# Exponential backoff: 10ms, 20ms, 40ms, 80ms, ...
$ retry --delay 10ms --delay-multiplier 2 /bin/sh -c "echo 'important work'"

Output

All child command output is piped to stdout/stderr. If the command exits non-zero, a summary is printed to stderr (unless --quiet is used). The exit code always matches the child's last exit code.

$ retry -d 10ms -m 2 sh -c "exit 1"

command `sh -c exit 1` exited with non-zero code (1) on attempt #1; retrying in 10ms
command `sh -c exit 1` exited with non-zero code (1) on attempt #2; retrying in 20ms
command `sh -c exit 1` exited with non-zero code (1) on attempt #3; retrying in 40ms
command `sh -c exit 1` exited with non-zero code (1) on attempt #4; retrying in 80ms
command `sh -c exit 1` exited with non-zero code (1) on attempt #5; maximum attempts reached

$ echo $?
1