netmiko:如何在新行中发送 get 命令输出
netmiko: How to sends get command output in a new line
这是脚本
from netmiko import ConnectHandler
cisco_device = {
'device_type': 'cisco_ios',
'ip': 'Router1',
'username': 'u',
'password': 'p'
}
net_connect = ConnectHandler(**cisco_device)
cmd = ['show clock', 'show version | include IOS']
output = ''
for command in cmd:
output += net_connect.send_command(command)
print(output)
输出
如您所见,输出显示在一行中
user@linux:~$ python script.py
*00:22:10.927 UTC Fri Mar 1 2002Cisco IOS Software, 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(15)T7, RELEASE SOFTWARE (fc3)
user@linux:~$
期望的输出
我想在一个新行中分隔每个输出
*00:23:31.943 UTC Fri Mar 1 2002
Cisco IOS Software, 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(15)T7, RELEASE
output = []
for command in cmd:
output.append(net_connect.send_command(command))
print(output[-1])
其他方法是在每行
上附加换行符 "\n"
output = ''
for command in cmd:
output += net_connect.send_command(command) + "\n"
print(output)
这是脚本
from netmiko import ConnectHandler
cisco_device = {
'device_type': 'cisco_ios',
'ip': 'Router1',
'username': 'u',
'password': 'p'
}
net_connect = ConnectHandler(**cisco_device)
cmd = ['show clock', 'show version | include IOS']
output = ''
for command in cmd:
output += net_connect.send_command(command)
print(output)
输出
如您所见,输出显示在一行中
user@linux:~$ python script.py
*00:22:10.927 UTC Fri Mar 1 2002Cisco IOS Software, 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(15)T7, RELEASE SOFTWARE (fc3)
user@linux:~$
期望的输出
我想在一个新行中分隔每个输出
*00:23:31.943 UTC Fri Mar 1 2002
Cisco IOS Software, 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(15)T7, RELEASE
output = []
for command in cmd:
output.append(net_connect.send_command(command))
print(output[-1])
其他方法是在每行
上附加换行符"\n"
output = ''
for command in cmd:
output += net_connect.send_command(command) + "\n"
print(output)