问题描述
限时送ChatGPT账号..如何在 shell 脚本中运行 telnet 并在远程服务器上执行命令?
How can I run telnet inside a shell script and execute commands on the remote server?
由于安全原因,我没有在我的solaris机器上安装expect.我也没有安装 perl net::telnet
模块.
I do not have expect installed on my solaris machine because of security reasons.
I also do not have the perl net::telnet
module installed.
如果不使用 expect 和 perl,我该怎么做?
So with out using expect and perl how can I do it?
我尝试了下面的方法,但它不起作用.
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.
>
推荐答案
您的某些命令可能会被丢弃.您可以使用普通的脚本结构实现更精细的控制,然后通过带有 echo
的管道发送所需的命令.将命令列表分组以创建一个会话":-
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
. 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
这篇关于在 shell 脚本中远程登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论