小编典典

因为stdin不是终端,所以不会分配伪终端

linux

我试图编写一个Shell脚本,该脚本在远程服务器上创建一些目录,然后使用scp将文件从本地计算机复制到远程服务器上。这是我到目前为止的内容:

ssh -t user@server<<EOT
DEP_ROOT='/home/matthewr/releases'
datestamp=$(date +%Y%m%d%H%M%S)
REL_DIR=$DEP_ROOT"/"$datestamp
if [ ! -d "$DEP_ROOT" ]; then
    echo "creating the root directory"
    mkdir $DEP_ROOT
fi
mkdir $REL_DIR
exit
EOT

scp ./dir1 user@server:$REL_DIR
scp ./dir2 user@server:$REL_DIR

每当我运行它时,我都会收到以下消息:

Pseudo-terminal will not be allocated because stdin is not a terminal.

脚本将永远挂起。

我的公钥在服务器上是受信任的,我可以在脚本之外运行所有命令。有任何想法吗?


阅读 623

收藏
2020-06-02

共1个答案

小编典典

尝试ssh -t -t(或ssh -tt简称)强制伪tty分配,即使stdin不是终端。

从ssh联机帮助页:

-T      Disable pseudo-tty allocation.

-t      Force pseudo-tty allocation.  This can be used to execute arbitrary 
        screen-based programs on a remote machine, which can be very useful,
        e.g. when implementing menu services.  Multiple -t options force tty
        allocation, even if ssh has no local tty.
2020-06-02