A utility for retrying failed CLI commands on Unix-like systems.
# 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'"
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