本文介绍了不会分配伪终端,因为 stdin 不是终端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个 shell 脚本,在远程服务器上创建一些目录,然后使用 scp 将文件从我的本地机器复制到远程服务器上.这是我到目前为止所拥有的:
I am trying to write a shell script that creates some directories on a remote server and then uses scp to copy files from my local machine onto the remote. Here's what I have so far:
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
每当我运行它时,我都会收到此消息:
Whenever I run it I get this message:
Pseudo-terminal will not be allocated because stdin is not a terminal.
脚本永远挂起.
我的公钥在服务器上是可信的,我可以在脚本之外运行所有命令就好了.有什么想法吗?
My public key is trusted on the server and I can run all the commands outside of the script just fine. Any ideas?
推荐答案
尝试 ssh -t -t
(或简称 ssh -tt
)强制伪 tty即使 stdin 不是终端也分配.
Try ssh -t -t
(or ssh -tt
for short) to force pseudo-tty allocation even if stdin isn't a terminal.
来自 ssh 联机帮助页:
From ssh manpage:
-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.
这篇关于不会分配伪终端,因为 stdin 不是终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!