Python Forum
netmiko: print out specific line matches with 'Cisco IOS Software' in sh ver output
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
netmiko: print out specific line matches with 'Cisco IOS Software' in sh ver output
#1
This is sample output of Cisco Switch show version command.

    Switch#show version
    Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE, RELEASE SOFTWARE (fc1)
    Technical Support: http://www.cisco.com/techsupport
    Copyright (c) 1986-2012 by Cisco Systems, Inc.
Objective: If string Cisco IOS Software is found in show version output, I would like to print the whole line.

To make it easier to understand, let me put show version output in variable shvar

    shvar = '''
    Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE, RELEASE SOFTWARE (fc1)
    Technical Support: http://www.cisco.com/techsupport
    Copyright (c) 1986-2012 by Cisco Systems, Inc.
    '''
Search with if

    >>> if 'Cisco IOS Software' in shvar:
    ...     print('Found ... print line')
    ... 
    Found ... print line
    >>> 
Or Search with find

    >>> if shvar.find('Cisco IOS Software') > 0:
    ...     print('Found ... print line')
    ... 
    Found ... print line
    >>> 
The question is how do I print the line matches with 'Cisco IOS Software'?

Desired Output

    Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE, RELEASE SOFTWARE (fc1)
Reply
#2
One option is to do : show version | incl IOS Software instead of just show version.
Then you are sure you only get that line..

Another option is using regex. I got an example on that specific somewhere, just cant find it right now. :(

/ carsten

(Apr-20-2020, 05:52 AM)sabrina Wrote: This is sample output of Cisco Switch show version command.

    Switch#show version
    Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE, RELEASE SOFTWARE (fc1)
    Technical Support: http://www.cisco.com/techsupport
    Copyright (c) 1986-2012 by Cisco Systems, Inc.
Objective: If string Cisco IOS Software is found in show version output, I would like to print the whole line.

To make it easier to understand, let me put show version output in variable shvar

    shvar = '''
    Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE, RELEASE SOFTWARE (fc1)
    Technical Support: http://www.cisco.com/techsupport
    Copyright (c) 1986-2012 by Cisco Systems, Inc.
    '''
Search with if

    >>> if 'Cisco IOS Software' in shvar:
    ...     print('Found ... print line')
    ... 
    Found ... print line
    >>> 
Or Search with find

    >>> if shvar.find('Cisco IOS Software') > 0:
    ...     print('Found ... print line')
    ... 
    Found ... print line
    >>> 
The question is how do I print the line matches with 'Cisco IOS Software'?

Desired Output

    Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE, RELEASE SOFTWARE (fc1)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  hello everyone, I am attempting to extract lldp neighbors from Cisco switches->excel skins996 1 2,959 Nov-13-2020, 04:29 PM
Last Post: evapa8f
  Netmiko Program ssh from the Jumpssh ( host -> Jumphost -> Network Device matya0403 3 6,770 Jul-31-2020, 08:22 AM
Last Post: dtw
  Connect to device without paramiko/netmiko modules kang18 3 3,001 Jun-05-2020, 10:54 AM
Last Post: Larz60+
  Netmiko timing out after sending command c7borg 0 9,408 Mar-25-2020, 04:53 PM
Last Post: c7borg
  netmiko connecting to arista devices. dan1962 0 4,070 Feb-07-2020, 09:23 PM
Last Post: dan1962
  GNS3 telnet from bash terminal to virtual cisco router marienbad 2 3,687 Feb-24-2019, 07:55 AM
Last Post: marienbad
  How to get specific output on interface? searching1 3 2,984 Dec-31-2018, 01:29 AM
Last Post: Larz60+
  Python script for show commands-CISCO Devices babbarsher 1 12,929 Dec-13-2017, 11:44 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020