netmiko

netmiko can't execute 'sh run | i host'

佐手、 提交于 2021-02-11 12:28:32
问题 I notice that my netmiko code can't run sh run | i host which is a legitimate Cisco command. When I replace sh run with other command such as sh clo , or show ip interface brief , it works perfectly. from netmiko import ConnectHandler R1 = { 'device_type': 'cisco_ios', 'ip': 'Router1', 'username': 'u', 'password': 'p' } R2 = { 'device_type': 'cisco_ios', 'ip': 'Router2', 'username': 'u', 'password': 'p' } all_devices = [R1, R2] for device in all_devices: connect = ConnectHandler(**device)

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

Deadly 提交于 2020-04-30 07:13:06
问题 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 As you can see, the output is displayed in a single line user@linux:~$ python script.py *00:22:10.927 UTC Fri Mar 1 2002Cisco IOS Software, 3700 Software