Skip to content

Instantly share code, notes, and snippets.

@sumimakito
Created October 30, 2017 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sumimakito/b27f8b2abbc7c63a20c4794165c9c74a to your computer and use it in GitHub Desktop.
Save sumimakito/b27f8b2abbc7c63a20c4794165c9c74a to your computer and use it in GitHub Desktop.
loop.sh [--expected EXIT_CODE] COMMANDS...
expected=0
command=$@
re='^[0-9]+$'
if [[ $1 == '--expected' ]] ; then
if ! [[ $2 =~ $re ]] ; then
echo "Error: expected exit code '$2' is invalid."
exit 1
else
expected=$2
command=${@:3}
fi
fi
$command
ret=$?
echo "Got exit code: $ret"
while [ $ret -ne $expected ]; do
echo "Not good! Try again!"
sleep 1
$command
ret=$?
echo "Got exit code: $ret"
done
echo "Exiting ..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment