Last active
March 20, 2017 14:52
-
-
Save padilo/942c8874b3f2fcc24de1394a80c6d187 to your computer and use it in GitHub Desktop.
bash script retry command every some seconds
This file contains hidden or 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
#!/usr/bin/env bash | |
if [ $# -ne 3 ]; then | |
echo 'usage: retry <num tries> <wait retry secs> \"<command>\"' | |
exit 1 | |
fi | |
tries=$1 | |
wait_retry=$2 | |
command=$3 | |
for i in `seq 1 $tries`; do | |
$command | |
ret_value=$? | |
[ $ret_value -eq 0 ] && break | |
echo \"> failed with $ret_value, waiting to retry...\" | |
sleep $wait_retry | |
done | |
exit $ret_value" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment