Skip to content

Instantly share code, notes, and snippets.

@emilisto
Last active December 20, 2015 03:19
Show Gist options
  • Save emilisto/6062551 to your computer and use it in GitHub Desktop.
Save emilisto/6062551 to your computer and use it in GitHub Desktop.
Little bash script that re-runs a command until it exits with code 0, i.e. runs successfully. I get impatient when SSH'ing to new servers...
#!/bin/bash
# Examples:
#
# When's the damn thing online?
#
# $ retry.sh ssh [email protected]
#
# When's internet back?
#
# $ retry.sh ping -c 1 google.com
#
ret=1
while [[ $ret -ne 0 ]]; do
$@
ret=$?
if [[ $ret -ne 0 ]]; then
sleep 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment