Last active
December 19, 2015 15:19
-
-
Save ryran/5975549 to your computer and use it in GitHub Desktop.
A simple bash function for retrying commands until they succeed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 'Loop' command | |
# I use this mostly for when machines are booting up and I don't want to | |
# keep manually trying to ssh over to them | |
function L { | |
local interval | |
if [[ $# -eq 0 || $1 = --help || $1 = -h || $1 = -\? ]]; then | |
echo "Usage: L [-N] COMMAND" | |
echo "Runs COMMAND [waiting N sec between failed attempts] until it succeeds" | |
echo "If wait interval N is not specified, it defaults to 2 sec" | |
else | |
[[ ${1#-} -gt 0 ]] && { interval=${1#-}; shift; } || interval=2 | |
until $@; do | |
sleep $interval | |
done | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment