简体   繁体   English

netmiko:如何在新行中发送获取命令 output

[英]netmiko: How to sends get command output in a new line

This is the script这是脚本

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)

Output Output

As you can see, the output is displayed in a single line如您所见,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:~$ 

Desired Output所需 Output

I would like to separate each output in a new line我想在新行中分隔每个 output

*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])

Other way would be appending newline "\n" on each line其他方式是在每一行添加换行符"\n"

output = ''
for command in cmd:
    output += net_connect.send_command(command) + "\n"

print(output)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM