Created
September 23, 2013 02:10
-
-
Save RWJMurphy/6665733 to your computer and use it in GitHub Desktop.
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
| function retry() { | |
| # retry [--limit,-l] [--delay,-d] [--] command args.. | |
| [ $# -lt 1 ] && echo "return [-ld] [--] commands [args...]" >&2 && return | |
| LIMIT=5 | |
| DELAY=5 | |
| while [[ $# > 0 ]]; do | |
| case $1 in | |
| --limit|-l) | |
| shift | |
| LIMIT=$1 | |
| ;; | |
| --delay|-d) | |
| shift | |
| DELAY=$1 | |
| ;; | |
| --) | |
| shift | |
| break | |
| ;; | |
| *) | |
| break | |
| ;; | |
| esac | |
| shift | |
| done | |
| command=$1;shift | |
| args="$*" | |
| success=1 | |
| while true; do | |
| $command $args | |
| success=$? | |
| [ $success -eq 0 ] && break | |
| let LIMIT-- | |
| [ $LIMIT -lt 1 ] && break | |
| sleep $DELAY | |
| done | |
| } |
Author
RWJMurphy
commented
Sep 23, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment