简体   繁体   English

在shell脚本中进行Telnet

[英]Telnet inside a shell script

How can I run telnet inside a shell script and execute commands on the remote server? 如何在shell脚本中运行telnet并在远程服务器上执行命令?

I do not have expect installed on my solaris machine because of security reasons. 由于安全原因,我不希望在我的solaris机器上安装。 I also do not have the perl net::telnet module installed. 我也没有安装perl net::telnet模块。

So with out using expect and perl how can I do it? 那么使用expect和perl我怎么能这样做?

I tried the below thing but its not working. 我尝试了以下的东西,但它不起作用。

#!/usr/bin/sh
telnet 172.16.69.116 <<!
user
password
ls
exit
!

When I execute it, this is what I am getting: 当我执行它时,这就是我得到的:

> cat tel.sh
telnet 172.16.69.116 <<EOF
xxxxxx
xxxxxxxxx
ls
exit
EOF
> tel.sh
Trying 172.16.69.116...
Connected to 172.16.69.116.
Escape character is '^]'.
Connection to 172.16.69.116 closed by foreign host.
> 

Some of your commands might be discarded. 您的某些命令可能会被丢弃。 You can achieve finer control with ordinary script constructs and then send required commands through a pipe with echo . 您可以使用普通脚本构造实现更好的控制,然后通过带有echo的管道发送所需的命令。 Group the list of commands to make one "session":- 将命令列表分组以进行一个“会话”: -

{
sleep 5
echo user
sleep 3
echo password
sleep 3
echo ls
sleep 5
echo exit
} | telnet 172.16.65.209

I had the same issue...however, at least in my environment it turned out being the SSL Certificate on the destination server was corrupted in some way and the server team took care of the issue. 我遇到了同样的问题......但是,至少在我的环境中,结果是目标服务器上的SSL证书在某种程度上被破坏了,服务器团队处理了这个问题。

Now, what I'm trying to do is to figure out how to get a script to run the exact same thing you're doing above except I want it to dump out the exact same scenario above into a file and then when it encounters a server in which it actually connects, I want it to provide the escape character (^]) and go on to the next server. 现在,我要做的是弄清楚如何让一个脚本运行你正在做的完全相同的事情,除了我希望它将上面完全相同的场景转储到一个文件中然后当它遇到一个它实际连接的服务器,我希望它提供转义字符(^])并继续下一个服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM