netmiko cant execute sh run | i host

2024/10/5 22:23:38

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 ConnectHandlerR1 = {'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?

Answer

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://en.xdnf.cn/q/119730.html

Related Q&A

How to dump the data from file to an excel sheet

I want to dump [3-4 lines together] some data to an excel sheet. I could able to dump single line based on some criteria [like if line is getting start with // or /* ], but in case of when lines starts…

I dont understand why my script is not iterating through all string.split elements?

The objective of this python exercise is to build a function that turns text into pig latin, a simple text transformation that modifies each word by moving the first character to the end and appending …

Unable to change the tick frequency on my chart

I have seen many questions on changing the tick frequency on SO, and that did help when I am building a line chart, but I have been struggling when its a bar chart. So below are my codes import numpy a…

Django Queryset foreign keys

I am trying to get a queryset but it is not displaying anything. Basically, I want to get the Asset objects that are assigned via foreign key to an employee, which is a foreign key of the signed in use…

How to reorder the columns of a CSV?

How can I re-order the columns of a CSV file using Python? These are the first rows of a CSV file I need to change:03;30269714;Ramiro Alberto;Nederz;active;pgc_gral 03;36185520;Andrea;Espare;active;pg…

Distance matrix in Python Pandas

I am a newbie in python, but I like to process data in pandas. I have a hundred pairs of CSV data such as passenger and bus stop data. The passenger structure data is Person, and XY coordinates (UTM-Me…

calculating catalan numbers using memoization

I am tring to use memoization in order to calculate catalan numbers, but it just does not seem to work, what do I need to change?def catalan_mem(n, memo = None):if n==0:return 1if memo == None:memo = …

cron python file doesnt work on centos 7

im trying to schedule my pythohn script into Centos 7 with cron. On my script at start i have added this:#!/usr/local/bin/pythonand this is my cron file that i have create into folder that contain pyth…

Comma separated Matrix from txt files - continued

I need to form a matrix from a list of textfiles containing frequency distribution of expressions. Therefore, I created a list of all that text files (lof) from a directory and used it to build a matri…

Questions about training LLMs on large text datasets for text generation from scratch

I made a fully custom made GPT in Jax (with Keras 3), using Tensorflow for the data pipeline. Ive trained the model on the Shakespeare dataset and got good results (so no problem with the model). Now I…