Created
July 25, 2012 17:08
-
-
Save gondoi/3177298 to your computer and use it in GitHub Desktop.
random host choice
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
| hostlist=("http://chef.rckspc.com" "http://s3.amazonaws.com") | |
| # Get command line arguments | |
| while getopts sarv: opt | |
| do | |
| case "$opt" in | |
| v) version="$OPTARG";; | |
| s) use_shell=1;; | |
| a) test -n "$host" && echo "Host already set to ${host}" || host="${hostlist[1]}";; | |
| r) test -n "$host" && echo "Host already set to ${host}" || host="${hostlist[0]}";; | |
| \?) # unknown flag | |
| echo >&2 \ | |
| "usage: $0 [-s] [-v version] [-r|-a]" | |
| exit 1;; | |
| esac | |
| done | |
| shift `expr $OPTIND - 1` | |
| index=$RANDOM | |
| let "index %= ${#hostlist[@]}" | |
| test -n "$host" || host=${hostlist[$index]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment