Python 脚本 - 连接到 SSH 并运行命令
我已经知道有 Python 的 ssh 模块,但这不是我正在寻找的。 我想要的是一个 python 脚本来执行以下操作:
- >连接到 [ 用户输入 ] SSH 主机
- >使用凭据[由用户提供]进行连接
- >在 SSH 主机上运行命令 [ telnet 到 [主机 - 用户输入 ]
- >在 telnet 会话中选择菜单项
提前致谢,
谨致问候,
I already know there are ssh modules for Python, that's not for what I'm looking for.
What I want to have is an python script to do the following:
- > connect to an [ input by user ] SSH host
- > connect using the credentials [ provided by the user ]
- > run command on the SSH host [ telnet to [host - input by user ]
- > Select menu item in the telnet session
Thanks in advance,
Best regards,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
使用
paramiko
,参见http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely- Different/ 通过使用它的示例。Use
paramiko
, see http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/ for a through example of using it.使用 paramiko 或 libssh2 python 绑定。
Use paramiko or the libssh2 python bindings.
现在流行的解决方案是 Fabric
now the popular solution is Fabric
如果您确实正在寻找一个可以自动执行 CLI 交互的模块,那么 pexpect
If you're actually looking for a module that lets you automate CLI interaction, there's pexpect
有很多图书馆可以做到这一点。
您可以查看他们的实现文档。
There are many libraries to do that.
You can check their documentation for the implementation.
我将向您推荐:
输出:
I will refer you to:
output:
您可以使用 vassal 包,它正是为此设计的。
您所需要做的就是安装vassal并执行
此操作,这将每秒运行该命令一次,并且您可以通过更改sec=0.1使其运行得更快。
You can use the vassal package, which is exactly designed for this.
All you need is to install vassal and do
This will run the command once every second, and you can make it run faster to change sec=0.1.