在 shell 脚本中远程登录

编程入门 行业动态 更新时间:2024-10-27 15:30:03
本文介绍了在 shell 脚本中远程登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-05-01 06:51:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405844.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   远程登录   shell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!