From: Colin P. Mccabe Date: Tue, 29 Nov 2016 23:12:23 +0000 (-0800) Subject: dssh: add the option to set (or not set) a controlling terminal. X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8618f68137593b789ec5a30b95b97f2170fea046;p=cmccabe-bin dssh: add the option to set (or not set) a controlling terminal. Basically, we want ssh's behavior, where the command will "just do the right thing" based on whether it is being run interactively or not. --- diff --git a/dssh b/dssh index 710fdac..7540c8b 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 @@ -41,6 +50,10 @@ if [ $# -eq 0 ]; then else RUN_COMMAND="${@}" fi +EXTRA_DOCKER_ARGS="" +if [ ${ALLOCATE_TTY} -ne 0 ]; then + EXTRA_DOCKER_ARGS="${EXTRA_DOCKER_ARGS} -t" +fi which docker &>/dev/null || die "docker must be on the PATH." @@ -61,4 +74,4 @@ else die "failed to find a docker image named ${DOCKER_IMAGE_NAME}" fi -docker exec -it "${DOCKER_IMAGE_ID}" ${RUN_COMMAND} +docker exec -i ${EXTRA_DOCKER_ARGS} "${DOCKER_IMAGE_ID}" ${RUN_COMMAND}