X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=dssh;h=9799ec0c3f9153cec8e14371f9445d19934281b9;hb=master;hp=a00ca4d8b7af6edfcc11057adf4029a3f95197a8;hpb=f1d171743a8d86cb67810fb4b97b79a0ce525eda;p=cmccabe-bin diff --git a/dssh b/dssh index a00ca4d..9799ec0 100755 --- a/dssh +++ b/dssh @@ -19,22 +19,37 @@ 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 exit 1;; esac done +shift $(expr $OPTIND - 1) +if [ $# -eq 0 ]; then + RUN_COMMAND="/bin/bash" +else + RUN_COMMAND="" +fi which docker &>/dev/null || die "docker must be on the PATH." @@ -55,4 +70,9 @@ else die "failed to find a docker image named ${DOCKER_IMAGE_NAME}" fi -docker exec -it "${DOCKER_IMAGE_ID}" /bin/bash +if [ ${ALLOCATE_TTY} == 1 ]; then + docker exec -it "${DOCKER_IMAGE_ID}" "${@}" ${RUN_COMMAND} +else + docker exec -i "${DOCKER_IMAGE_ID}" "${@}" ${RUN_COMMAND} & + wait +fi