X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=dssh;h=9799ec0c3f9153cec8e14371f9445d19934281b9;hb=216993683b06009481be24fedcff59a9bd6fea72;hp=710fdacdbc2ee78819ebfc0560cfe5b0ee2413ff;hpb=952f54e48416e47645cd277de86774525e74c40f;p=cmccabe-bin diff --git a/dssh b/dssh index 710fdac..9799ec0 100755 --- a/dssh +++ b/dssh @@ -19,16 +19,25 @@ options: -h: show this help message. -i [ID]: ssh into a docker node with this container ID -n [name]: ssh into a docker node with this name +-t [0 or 1]: 0 to avoid allocating a TTY; 1 to allocate one. + The default will be set based on whether this appears + to be an interactive shell. EOF } DOCKER_IMAGE_ID="" DOCKER_IMAGE_NAME="" -while getopts "hi:n:" flag; do +if [ -t 0 ]; then + ALLOCATE_TTY=1 +else + ALLOCATE_TTY=0 +fi +while getopts "hi:n:t:" flag; do case $flag in h) usage; exit 0;; i) DOCKER_IMAGE_ID=${OPTARG};; n) DOCKER_IMAGE_NAME=${OPTARG};; + t) ALLOCATE_TTY=${OPTARG};; *) echo "getopts error" echo usage @@ -39,7 +48,7 @@ shift $(expr $OPTIND - 1) if [ $# -eq 0 ]; then RUN_COMMAND="/bin/bash" else - RUN_COMMAND="${@}" + RUN_COMMAND="" fi which docker &>/dev/null || die "docker must be on the PATH." @@ -61,4 +70,9 @@ else die "failed to find a docker image named ${DOCKER_IMAGE_NAME}" fi -docker exec -it "${DOCKER_IMAGE_ID}" ${RUN_COMMAND} +if [ ${ALLOCATE_TTY} == 1 ]; then + docker exec -it "${DOCKER_IMAGE_ID}" "${@}" ${RUN_COMMAND} +else + docker exec -i "${DOCKER_IMAGE_ID}" "${@}" ${RUN_COMMAND} & + wait +fi