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)
    output = connect.send_command('sh run | i host')
    print(output)

Output

user@linux:~$ python3 script.py 
^
% Invalid input detected at '^' marker.

^
% Invalid input detected at '^' marker.

user@linux:~$ 

Desired Output

hostname Router1
hostname Router2

Any idea why this code behave this way?


回答1:


sh run is short for show running-config; this is a privileged-mode command (requires enable first) and you're trying to issue it in unprivileged mode.



来源:https://stackoverflow.com/questions/61222731/netmiko-cant-execute-sh-run-i-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!