cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
513
Views
1
Helpful
2
Replies

Enter comments between outputs from Show Commands using Python

CiscoPurpleBelt
Level 6
Level 6

I want to be able to enter comments before each output for the show commands listed in the list in my Python script. For instance, before the 'show ip int br' output is displayed I would like it to read "check these interfaces" or "this is from test device, etc. etc.

Right now it just display output of "show ip int br" then directly after "show interface status" etc.

Any help??

Here is my working script:

 

import netmiko
from netmiko import ConnectHandler
import getpass
import sys
 
MySwitch = {
    'device_type': 'cisco_ios',
    'ip': '172.16.1.1,
    'username': 'username',
    'password': 'password',
    }
 
MySwitch['username']=input("User name ")
MySwitch['password']=getpass.getpass()
print("Enter enable password: ")
MySwitch['secret']=getpass.getpass()

cmd = ['show ip int brief', 'show interface status', 'show processes']
output = ''


 
net_connect = ConnectHandler(**MySwitch)

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

print(output)
print('Closing Connection')
net_connect.disconnect()

 

2 Replies 2

Hi

 Put another print() before

print("You message here")

print(output)

You mean like this?

cmd = ['show ip int brief''show interface status''show processes']
print("comment 1") 
output = ''
 
 
Haven't tried it yet but given I am using a list wouldn't it run all the commands in the list first or no?