SSH 与 Paramiko:无法读取数据
下面是我的驱动程序信息,我需要使用 ssh 脚本提取数据(固件版本),如下所示。
ncmdvstk:~ $ ssh [email protected]
Password:
MSM760 V. 5.3.6.18-01-9124
(C) 2010 Hewlett-Packard Development Company, L.P.
CLI> enable
CLI# show system info
[CPU info] [Mem in fo]
Firmware Version: 5.3.6.18-01-9124 Load 1min: 0.34 Total RAM: 9
这是我用来首先读取“数据”变量中的所有数据的程序,以便稍后我可以拆分 n 获取我需要的信息,但在打印数据中没有打印数据:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('153.88.127.21', username='admin',password='catfish')
stdin, stdout, stderr = ssh.exec_command("enable")
stdin.write('show system info \n')
data = stdout.read()
print data
请纠正我获取数据的问题。
Below is my driver information where I need to pull the data(Firmware Version) using ssh script as show below.
ncmdvstk:~ $ ssh [email protected]
Password:
MSM760 V. 5.3.6.18-01-9124
(C) 2010 Hewlett-Packard Development Company, L.P.
CLI> enable
CLI# show system info
[CPU info] [Mem in fo]
Firmware Version: 5.3.6.18-01-9124 Load 1min: 0.34 Total RAM: 9
This is the program I am using to read all the data first in "data" variable, so that later i can split n get info i need but where as no data it's printing in print data:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('153.88.127.21', username='admin',password='catfish')
stdin, stdout, stderr = ssh.exec_command("enable")
stdin.write('show system info \n')
data = stdout.read()
print data
Please correct me on getting the data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在
stdin.write()
之后添加对stdin.flush()
的调用,否则您发送的输入将保持缓冲状态。You need to add a call to
stdin.flush()
after thestdin.write()
otherwise the input you're sending will stay buffered.