linux - 不会分配伪终端,因为 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.

脚本永远挂起。

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

最佳答案

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

另请参阅:Terminating SSH session executed by bash script

来自 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.

https://stackoverflow.com/questions/7114990/

相关文章:

list - 连接两个列表 - '+=' 和 extend() 之间的区别

python - 什么时候 "i += x"与 Python 中的 "i = i + x"不同?

python - 转义正则表达式字符串

linux - 如何从 iptables 中删除特定规则?

python - 如何使用 matplotlib 在 while 循环中实时绘图?

linux - 在每行的开头添加前缀字符串

python - cron 和 virtualenv

linux - 如何在不输入 'screen' 的情况下退出 'exit' ?

windows - Windows 和 Linux 目录名称中禁止使用哪些字符?

python - 在多个模块中使用日志记录