linux - SSH 在没有连接到 shell 脚本中的服务器的情况下退出

标签 linux bash unix ssh

我正在尝试连接到服务器并进入每个目录。但是当我尝试通过 SSH 连接到第一台服务器 server1 时,它给我的错误是

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

这是下面的配置文件和 bash 脚本:

getPatches.cfg

SERVERLIST="server1;server2"
USERNAME=bob
DIRECTORY=/net/bob

脚本

#!/bin/sh

CFGFILE=getPatches.cfg

if ! [ -f $CFGFILE ] ; then
   echo "ERROR: $CFGFILE configuration file is missing"
   exit 1
fi
# READ $CFGFILE
. $CFGFILE
servers=$SERVERLIST
user=$USERNAME
directory=$DIRECTORY

#Tokenize ServerList
while IFS=';' read -ra ADDR; do
        for i in "${ADDR[@]}"; do
                ssh $user@$i
                AccessIntoDirectory="cd $directory"
                export AccessIntoDirectory
                ssh -q $i $AccessIntoDirectory
        done
done <<< "$servers"

我已经生成了一个 SSH 公钥,这个脚本应该做的是通过 SSH 连接到服务器并 cd 到我想要的目录,但是它退出了并且没有通过 SSH 连接到服务器。任何帮助都会很棒!

最佳答案

在不使用控制台(tty)的情况下使用 ssh 命令的解决方案是添加 -t -t 选项。

ssh -t -t $user@$i

关于linux - SSH 在没有连接到 shell 脚本中的服务器的情况下退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24523883/

相关文章:

python - Ubuntu 14.04 上的 Vim 使用了一个有趣的 python 路径,python 无法在其他模块中导入 _io

bash - for 循环中的 shell 脚本 sum 不起作用

linux - 手动触发正在等待信号的休眠 bash 脚本

linux - 从文件中读取字符串,在另一个文件中找到该字符串的第一个匹配项

linux - shell 脚本 : execute echo statements with a time delay

mysql - 无法连接到MySQL服务器错误111

c++ - 如何使用 recv() 在 C++ 套接字中接收超过 65000 个字节

linux - shell脚本中的命令返回

bash - bash 中的 $(shell) 引用

linux - ncat web服务器如何获取请求参数和客户端ip