<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python Script to show interface name and input status never in Network Devices</title>
    <link>https://community.cisco.com/t5/network-devices/python-script-to-show-interface-name-and-input-status-never/m-p/3953623#M267</link>
    <description>&lt;P&gt;Hi Thanks for the response but I was running the sh interface command and then wanting to return the interfaces and the Last Input status never for all interfaces that matched.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran the regex you provided and it returned only the first interface but that actually had traffic showing on the last input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you provide any other advise?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Nov 2019 20:57:58 GMT</pubDate>
    <dc:creator>Delboy82</dc:creator>
    <dc:date>2019-11-05T20:57:58Z</dc:date>
    <item>
      <title>Python Script to show interface name and input status never</title>
      <link>https://community.cisco.com/t5/network-devices/python-script-to-show-interface-name-and-input-status-never/m-p/3953273#M265</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im trying to write a script which SSH to a switch runs the show interface name and the using regex pulls back interface name and Last input never&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;unfortunately i'm struggling with re module and my regex.&amp;nbsp; I have included an example regex and interface output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assistance would be appreciated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regex =&amp;nbsp;(^GigabitEthernet\d.\d.\d+)*(Last input never)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GigabitEthernet1/0/1 is down, line protocol is down (notconnect)&lt;BR /&gt;Hardware is Gigabit Ethernet, address is 5c5a.c7db.8401 (bia 5c5a.c7db.8401)&lt;BR /&gt;MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec,&lt;BR /&gt;reliability 255/255, txload 1/255, rxload 1/255&lt;BR /&gt;Encapsulation ARPA, loopback not set&lt;BR /&gt;Keepalive set (10 sec)&lt;BR /&gt;Auto-duplex, Auto-speed, media type is 10/100/1000BaseTX&lt;BR /&gt;input flow-control is off, output flow-control is unsupported&lt;BR /&gt;ARP type: ARPA, ARP Timeout 04:00:00&lt;BR /&gt;Last input 3d17h, output 3d17h, output hang never&lt;BR /&gt;Last clearing of "show interface" counters never&lt;BR /&gt;Input queue: 0/2000/0/0 (size/max/drops/flushes); Total output drops: 20&lt;BR /&gt;Queueing strategy: Class-based queueing&lt;BR /&gt;Output queue: 0/40 (size/max)&lt;BR /&gt;5 minute input rate 0 bits/sec, 0 packets/sec&lt;BR /&gt;5 minute output rate 0 bits/sec, 0 packets/sec&lt;BR /&gt;15579948 packets input, 3570223902 bytes, 0 no buffer&lt;BR /&gt;Received 40406 broadcasts (36191 multicasts)&lt;BR /&gt;3 runts, 0 giants, 0 throttles&lt;BR /&gt;0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored&lt;BR /&gt;0 watchdog, 36191 multicast, 0 pause input&lt;BR /&gt;0 input packets with dribble condition detected&lt;BR /&gt;46034823 packets output, 30241513330 bytes, 0 underruns&lt;BR /&gt;0 output errors, 0 collisions, 2 interface resets&lt;BR /&gt;846 unknown protocol drops&lt;BR /&gt;0 babbles, 0 late collision, 0 deferred&lt;BR /&gt;0 lost carrier, 0 no carrier, 0 pause output&lt;BR /&gt;0 output buffer failures, 0 output buffers swapped out&lt;BR /&gt;GigabitEthernet1/0/2 is up, line protocol is up (connected)&lt;BR /&gt;Hardware is Gigabit Ethernet, address is 5c5a.c7db.8402 (bia 5c5a.c7db.8402)&lt;BR /&gt;Description: Airtame - IS MR&lt;BR /&gt;MTU 1500 bytes, BW 100000 Kbit/sec, DLY 100 usec,&lt;BR /&gt;reliability 255/255, txload 1/255, rxload 1/255&lt;BR /&gt;Encapsulation ARPA, loopback not set&lt;BR /&gt;Keepalive set (10 sec)&lt;BR /&gt;Full-duplex, 100Mb/s, media type is 10/100/1000BaseTX&lt;BR /&gt;input flow-control is off, output flow-control is unsupported&lt;BR /&gt;ARP type: ARPA, ARP Timeout 04:00:00&lt;BR /&gt;Last input 00:02:13, output 00:00:00, output hang never&lt;BR /&gt;Last clearing of "show interface" counters never&lt;BR /&gt;Input queue: 0/2000/0/0 (size/max/drops/flushes); Total output drops: 5120&lt;BR /&gt;Queueing strategy: Class-based queueing&lt;BR /&gt;Output queue: 0/40 (size/max)&lt;BR /&gt;5 minute input rate 2000 bits/sec, 1 packets/sec&lt;BR /&gt;5 minute output rate 30000 bits/sec, 13 packets/sec&lt;BR /&gt;13045309 packets input, 2021942198 bytes, 0 no buffer&lt;BR /&gt;Received 3860583 broadcasts (3860553 multicasts)&lt;BR /&gt;0 runts, 0 giants, 0 throttles&lt;BR /&gt;25 input errors, 13 CRC, 0 frame, 0 overrun, 0 ignored&lt;BR /&gt;0 watchdog, 3860553 multicast, 2 pause input&lt;BR /&gt;0 input packets with dribble condition detected&lt;BR /&gt;55395593 packets output, 18496291841 bytes, 0 underruns&lt;BR /&gt;0 output errors, 0 collisions, 2 interface resets&lt;BR /&gt;0 unknown protocol drops&lt;BR /&gt;0 babbles, 0 late collision, 0 deferred&lt;BR /&gt;0 lost carrier, 0 no carrier, 0 pause output&lt;BR /&gt;0 output buffer failures, 0 output buffers swapped out&lt;BR /&gt;GigabitEthernet1/0/3 is down, line protocol is down (notconnect)&lt;BR /&gt;Hardware is Gigabit Ethernet, address is 5c5a.c7db.8403 (bia 5c5a.c7db.8403)&lt;BR /&gt;MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec,&lt;BR /&gt;reliability 255/255, txload 1/255, rxload 1/255&lt;BR /&gt;Encapsulation ARPA, loopback not set&lt;BR /&gt;Keepalive set (10 sec)&lt;BR /&gt;Auto-duplex, Auto-speed, media type is 10/100/1000BaseTX&lt;BR /&gt;input flow-control is off, output flow-control is unsupported&lt;BR /&gt;ARP type: ARPA, ARP Timeout 04:00:00&lt;BR /&gt;Last input never, output never, output hang never&lt;BR /&gt;Last clearing of "show interface" counters never&lt;BR /&gt;Input queue: 0/2000/0/0 (size/max/drops/flushes); Total output drops: 0&lt;BR /&gt;Queueing strategy: Class-based queueing&lt;BR /&gt;Output queue: 0/40 (size/max)&lt;BR /&gt;5 minute input rate 0 bits/sec, 0 packets/sec&lt;BR /&gt;5 minute output rate 0 bits/sec, 0 packets/sec&lt;BR /&gt;30860 packets input, 4744663 bytes, 0 no buffer&lt;BR /&gt;Received 1536 broadcasts (597 multicasts)&lt;BR /&gt;0 runts, 0 giants, 0 throttles&lt;BR /&gt;0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored&lt;BR /&gt;0 watchdog, 597 multicast, 0 pause input&lt;BR /&gt;0 input packets with dribble condition detected&lt;BR /&gt;128760 packets output, 116209358 bytes, 0 underruns&lt;BR /&gt;0 output errors, 0 collisions, 2 interface resets&lt;BR /&gt;18 unknown protocol drops&lt;BR /&gt;0 babbles, 0 late collision, 0 deferred&lt;BR /&gt;0 lost carrier, 0 no carrier, 0 pause output&lt;BR /&gt;0 output buffer failures, 0 output buffers swapped out&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2019 11:01:57 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-devices/python-script-to-show-interface-name-and-input-status-never/m-p/3953273#M265</guid>
      <dc:creator>Delboy82</dc:creator>
      <dc:date>2019-11-05T11:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to show interface name and input status never</title>
      <link>https://community.cisco.com/t5/network-devices/python-script-to-show-interface-name-and-input-status-never/m-p/3953279#M266</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;Try the following.It uses a named capture group so you can retrieve the interface name when you have a match:&lt;/P&gt;
&lt;PRE&gt;import re

m = re.search("(?P&amp;lt;interface&amp;gt;GigabitEthernet\d.\d.\d+).*Last input never", cli_input, re.DOTALL)
if m:
    print(m.group("interface"))

&lt;/PRE&gt;
&lt;P&gt;'cli_input' is the string output of &lt;STRONG&gt;sh int gi1/1/1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cheers,&lt;/P&gt;
&lt;P&gt;Seb.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2019 11:30:40 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-devices/python-script-to-show-interface-name-and-input-status-never/m-p/3953279#M266</guid>
      <dc:creator>Seb Rupik</dc:creator>
      <dc:date>2019-11-05T11:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to show interface name and input status never</title>
      <link>https://community.cisco.com/t5/network-devices/python-script-to-show-interface-name-and-input-status-never/m-p/3953623#M267</link>
      <description>&lt;P&gt;Hi Thanks for the response but I was running the sh interface command and then wanting to return the interfaces and the Last Input status never for all interfaces that matched.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran the regex you provided and it returned only the first interface but that actually had traffic showing on the last input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you provide any other advise?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2019 20:57:58 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-devices/python-script-to-show-interface-name-and-input-status-never/m-p/3953623#M267</guid>
      <dc:creator>Delboy82</dc:creator>
      <dc:date>2019-11-05T20:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to show interface name and input status never</title>
      <link>https://community.cisco.com/t5/network-devices/python-script-to-show-interface-name-and-input-status-never/m-p/3953694#M268</link>
      <description>&lt;P&gt;Ah my mistake, I didn't notice the string contained multiple interfaces... Ok so we need to break it up per-interface then run a the final regex check:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;import re

for m1 in re.finditer("(GigabitEthernet\d.\d.\d+).*?buffers swapped out", cli_input, re.DOTALL):
        m2 = re.search("(GigabitEthernet\d.\d.\d+).*Last input never", m1.group(0), re.DOTALL)
        if m2:
            print(m2.group(0))
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...better?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cheers,&lt;/P&gt;
&lt;P&gt;Seb.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2019 22:21:01 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-devices/python-script-to-show-interface-name-and-input-status-never/m-p/3953694#M268</guid>
      <dc:creator>Seb Rupik</dc:creator>
      <dc:date>2019-11-05T22:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to show interface name and input status never</title>
      <link>https://community.cisco.com/t5/network-devices/python-script-to-show-interface-name-and-input-status-never/m-p/3954268#M269</link>
      <description>&lt;P&gt;Hi Thanks for your response its better but not quite what i was after i was really looking for the output of:&amp;nbsp; GigabitEthernet1/0/X&amp;nbsp; &amp;nbsp;Last Input Never in to group so i could call just the interface names and then i can run configurations against the interfaces that dont have any input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 19:36:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-devices/python-script-to-show-interface-name-and-input-status-never/m-p/3954268#M269</guid>
      <dc:creator>Delboy82</dc:creator>
      <dc:date>2019-11-06T19:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to show interface name and input status never</title>
      <link>https://community.cisco.com/t5/network-devices/python-script-to-show-interface-name-and-input-status-never/m-p/3954305#M270</link>
      <description>&lt;P&gt;Hold on, not so fast! we can do that with a little tweak... :&lt;/P&gt;
&lt;PRE&gt;targets = []
for m1 in re.finditer("(GigabitEthernet\d.\d.\d+).*?buffers swapped out", cli_input, re.DOTALL):
        m2 = re.search("(?P&amp;lt;interface&amp;gt;GigabitEthernet\d.\d.\d+).*Last input never", m1.group(0), re.DOTALL)
        if m2:
            targets.append(m2.group("interface"))

print(targets)
&lt;/PRE&gt;
&lt;P&gt;At the end of the run the list 'targets' will contain the interface names of all those with state 'Last input never'. You can then pass that list to another part of your script, iterate through it and run actions on each element.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cheers,&lt;/P&gt;
&lt;P&gt;Seb.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 20:40:01 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-devices/python-script-to-show-interface-name-and-input-status-never/m-p/3954305#M270</guid>
      <dc:creator>Seb Rupik</dc:creator>
      <dc:date>2019-11-06T20:40:01Z</dc:date>
    </item>
  </channel>
</rss>

