由于stdin不是终端,因此不会分配伪终端

我正在尝试编写一个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.

脚本永远挂起。


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


鸿蒙传说
浏览 1006回答 3
3回答

弑天下

即使stdin不是终端,也要尝试ssh -t -t(或ssh -tt简称)强制伪tty分配。从ssh手册页:-T&nbsp; &nbsp; &nbsp; Disable pseudo-tty allocation.-t&nbsp; &nbsp; &nbsp; Force pseudo-tty allocation.&nbsp; This can be used to execute arbitrary&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; screen-based programs on a remote machine, which can be very useful,&nbsp; &nbsp; &nbsp; &nbsp; e.g. when implementing menu services.&nbsp; Multiple -t options force tty&nbsp; &nbsp; &nbsp; &nbsp; allocation, even if ssh has no local tty.
打开App,查看更多内容
随时随地看视频慕课网APP