Skip to content

Instantly share code, notes, and snippets.

@gondoi
Created July 25, 2012 17:08
Show Gist options
  • Select an option

  • Save gondoi/3177298 to your computer and use it in GitHub Desktop.

Select an option

Save gondoi/3177298 to your computer and use it in GitHub Desktop.
random host choice
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