我正在尝试编写一个脚本,以便我可以登录到一个具有48个端口的控制台服务器上,以便我可以快速确定哪些设备连接到了每条串行线路。
基本上,我想要能够有一个脚本,给定主机/端口列表,可以 telnet 到列表中的第一个设备并将我留在交互模式下,以便我可以登录并确认设备,然后当我关闭 telnet 会话时,连接到列表中的下一个会话。
我遇到的问题是,如果我在可执行的 bash 脚本内部启动 telnet 会话,则会话立即终止,而不是等待输入。
例如,给定以下代码:
$ cat ./telnetTest.sh
#!/bin/bash
while read line
do
telnet $line
done
$
当我运行命令'echo "hostname" | testscript.sh'时,我收到以下输出:
$ echo "testhost" | ./telnetTest.sh
Trying 192.168.1.1...
Connected to testhost (192.168.1.1).
Escape character is '^]'.
Connection closed by foreign host.
$
有没有办法停止telnet会话自动关闭?