我正在写一个脚本ssh到与Paramiko设备,运行一个命令并解析该命令的输出。我已经玩过几个解析器,它似乎挂了。下面是代码为我在SSH:使用Paramiko ssh并运行一个命令,然后打印出解析
SSH
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
client.connect('127.0.0.1', username='foobar', password='foobar1')
stdin, stdout, stderr = client.exec_command('foo')
print stdout.read()
client.close()
示例输出运行指令FOO
C Processor:12-13-13 09:53:28 -- A Processor Initiated Reset
# Active Alarms:
12-13-13 09:53:40 -- App Select Required
# Device Settings - Port 1
MAC Address 00:00:00:00:0A:DF
IP Address 127.0.0.1
SubnetMask 155.155.155.0
AAAA Server Enabled
AAAA Server IP Pool Start 127.0.0.1
AAAA Server IP Pool End 127.0.0.1
AAAA Server Default Gateway 0.0.0.0
# Device Settings - Port 2
MAC Address 00:00:00:00:0A:E0
IP Address 127.0.0.1
SubnetMask 155.155.155.0
AAAA Server Enabled
AAAA Server IP Pool Start 127.0.0.1
AAAA Server IP Pool End 127.0.0.1
AAAA Server Default Gateway 0.0.0.0
Default Gateway 0.0.0.0
# Device Settings - Routing Table
Route #1 - Disabled
Route #2 - Disabled
Route #3 - Disabled
Route #4 - Disabled
Route #5 - Disabled
Route #6 - Disabled
Route #7 - Disabled
Route #8 - Disabled
.....(there is another 50 lines of code same format)
如果有人能指出我的帖子或网站与关于如何将其解析为文本文件的一些输入,这将非常棒。提前致谢!
什么您解析到文本文件的意思?你想写这个文本文件吗? – 2014-01-06 14:48:23
@Drt对不起,是的,现在我只想写这个输出到一个文件。后来我将它保存到数据库 – tjoenz