Skip to content

Instantly share code, notes, and snippets.

@padilo
Last active March 20, 2017 14:52
Show Gist options
  • Save padilo/942c8874b3f2fcc24de1394a80c6d187 to your computer and use it in GitHub Desktop.
Save padilo/942c8874b3f2fcc24de1394a80c6d187 to your computer and use it in GitHub Desktop.
bash script retry command every some seconds
#!/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