Show “free” (not used for a while) ports on Cisco switch with one command

Reasonably common task I come accross is to find free ports on switches (ports that havent been used for sometime). Sometimes its very easy where you can use an NMS or similar to give you a pretty output to show ports and their last input/output. However in my experience this is the exception rather than the rule. Heres a couple of examples using the pipe “|” to parse the output down a bit to only show us interfaces we want. All example shown have been tested on 2900, 3750 and 6500 switches running IOS 12.2+ (you should always check the switches uptime before taking these outputs to mean anything). Thanks to Steve B for suggesting “i proto” rather than “i GigabitE” to catch all flavours of interface.

This example shows all interfaces followed by the last input/output no matter if they are used or not.

Command: show int | i proto|Last in

Example of output

m00nie_cat#show int | i proto|Last in
GigabitEthernet1/1 is down, line protocol is down (notconnect)
  Last input 6w6d, output 6w6d, output hang never
GigabitEthernet1/2 is down, line protocol is down (notconnect)
  Last input 21w1d, output 21w1d, output hang never
GigabitEthernet1/3 is up, line protocol is up (connected)
  Last input 00:00:00, output 00:00:24, output hang never
GigabitEthernet1/4 is up, line protocol is up (connected)
  Last input 00:00:58, output 00:00:24, output hang never
GigabitEthernet1/5 is down, line protocol is down (notconnect)
  Last input never, output never, output hang never

This example is my favourite. Shows only admin down or unconnected ports that have no input/input for +6 weeks

Command: show int | i proto.*notconnect|proto.*administratively down|Last in.* [6-9]w|Last in.*[0-9][0-9]w|[0-9]y|disabled|Last input never, output never, output hang never

Example of output

m00nie_cat#$ in.* [6-9]w|Last in.*[0-9][0-9]w|[0-9]y|Last input never, output never, output hang never
  Last input never, output never, output hang never
GigabitEthernet1/1 is down, line protocol is down (notconnect)
  Last input 6w6d, output 6w6d, output hang never
GigabitEthernet1/2 is down, line protocol is down (notconnect)
  Last input 21w1d, output 21w1d, output hang never
GigabitEthernet1/5 is down, line protocol is down (notconnect)
  Last input never, output never, output hang never

There are some exceptions here where a port that is unconnected but used more recently than 6 weeks. These ports will show as below. They wont have any input/output info directly below them. I find for a very quick simple way to see free ports this works pretty well without having to mess about with other scripts. It might also show other port types (SVI, portchannel etc) that are down or have no input/output but this is quite rare in my experience.

Small caveat output

GigabitEthernet2/8 is down, line protocol is down (notconnect)
  Last input never, output never, output hang never
GigabitEthernet2/17 is down, line protocol is down (notconnect)
GigabitEthernet2/18 is down, line protocol is down (notconnect)
GigabitEthernet2/20 is down, line protocol is down (notconnect)

The 2nd command above isnt exactly easy to type/remember but used with an alias its pretty good!

m00nie_cat#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
m00nie_cat(config)#al
m00nie_cat(config)#ali
m00nie_cat(config)#alias ex
m00nie_cat(config)#alias exec free show int | i proto.*notconnect|proto.*administratively down|Last in.* [6-9]w|Last in.*[0-9][0-9]w|[0-9]y|Last input never, output never, output hang never
m00nie_cat(config)#^Z
m00nie_cat#free

GigabitEthernet1/1 is down, line protocol is down (notconnect)
  Last input 6w6d, output 6w6d, output hang never
GigabitEthernet1/2 is down, line protocol is down (notconnect)
  Last input 21w1d, output 21w1d, output hang never
GigabitEthernet1/5 is down, line protocol is down (notconnect)
  Last input never, output never, output hang never

Some more info about the pipe command and regex can be found in [this post].

m00nie 😀

Comments

  • I’ve always just done the first one but use “inc proto|Last” as the word protocol only appears on the Interface line and that way it doesn’t matter if it’s Fast,Gig etc.

    Nice RegEx example though, makes my head hurt working them out so like the see examples to copy!

  • Hi Steve

    Thanks for the suggestion 🙂 I’ve updated the post to change the “i GigabitE” to “i proto”.
    Glad you found the regex of some use.

    m00nie

  • #show int | i fastE.*notconnect|fastE.*administratively down|Last in.* [6-9]w|Last in.*[0-9][0-9]w|[0-9]y|Last input never, output never, output hang never
    from this, cant i found abour fastetharnet ports?
    i use it with FastE insterd of GigabiteE. but out put never show any Fa. port

    my output
    Last input never, output 34w0d, output hang never
    Last input never, output 1y25w, output hang never
    Last input never, output 26w1d, output hang never
    Last input never, output 1y25w, output hang never
    Last input 1y10w, output 00:00:01, output hang never
    Last input never, output 1y25w, output hang never
    Last input never, output 1y25w, output hang never
    Last input never, output 1y25w, output hang never
    Last input never, output 1y25w, output hang never
    Last input never, output 1y25w, output hang never
    Last input never, output 1y25w, output hang never
    Last input never, output 1y25w, output hang never

  • Hi Irfan

    Its probably the small f of fastE that needs changed to a capital. eg show int | i FastE|Last in
    I’ve tried this on an 1801 with fa ports and it worked no probs. Glad you got it working with Steve’s suggestion though 🙂

    m00nie

  • Thanks for this. However, when I run the commands my “output” for live ports is always something like 00:00:00 or something very, very small. Is there logging that needs to be enabled to keep track of the output?

  • Awesome I’ve searched on and off for years every time I need to consolidate switch ports, this will save me some time!

  • Hi Cffit

    Thats just the last time since the interface passed traffic. If you post an example I can maybe explain better 🙂

    m00nie

  • I understand now, thanks! I notice for a just a few there is no information. For instance here it lists the port for FastEthernet4/0/16, but there is no second line stating the inputs or outputs. Any ideas?

    FastEthernet4/0/14 is down, line protocol is down (notconnect)
    Last input never, output 16w4d, output hang never
    FastEthernet4/0/15 is down, line protocol is down (notconnect)
    Last input never, output 1y11w, output hang never
    FastEthernet4/0/16 is down, line protocol is down (notconnect)
    FastEthernet4/0/18 is down, line protocol is down (notconnect)
    Last input never, output 16w1d, output hang never
    FastEthernet4/0/23 is down, line protocol is down (notconnect)
    Last input never, output never, output hang never
    FastEthernet4/0/24 is down, line protocol is down (notconnect)
    Last input never, output never, output hang never

  • Nice command and alias ! 🙂

    but, one pbm (:D) i’m lost with regEX 🙁

    i just want to show “free” ports not used for 10 weeks mininum

    what i must change ? thx !

  • Hi Tetz

    Thanks and glad you’ve found it some use. If you just want 10+ weeks just remove the section “Last in.* [6-9]w”.
    Cheers

    m00nie 🙂

  • Thx !

    works perfectly !

    FYI : i use rancid and with a shell script and your command i can work so quickly to find which swichtes are empty slots or not 😀

  • Very nice, thanks.

    show int | i proto.*down|Last in.*(([0-9]y)*([0-9])*[6-9]w|[1-9]y|put never, output n)
    show int accounting | i Fast|No traffic

  • Hi m00nie, I used command that you suggested – thanks very much that was very helpful. But i have one question : when you get info from switch :

    GigabitEthernet1/0/3 is up, line protocol is up (connected)
    Last input 00:00:28, output 00:00:01, output hang never

    GigabitEthernet1/0/5 is up, line protocol is up (connected)
    Last input never, output 00:00:00, output hang never

    3-5 ports are up but one have the input other don’t.

    Could you explane me, what thouse numbers meen? 00:00:28 , 00:00:01, 00:00:00.
    And why one has input output numbers other only output?

  • Hi Mike

    Its simply just that there has either been some input and no output or some output and no input 🙂
    Hope that helps to clarify
    Cheers

    m00nie

  • Hi m00nie,

    If it says this……….

    Last input 24w4d, output 00:00:01, output hang never

    ……..is it safe to say the port has not been used for 24 weeks and 4 days ? What about the output 00:00:01 ? Does this not mean it has had output and thus can’t be considered unused ?

    Your help appreciated.
    Thanks
    Tony

  • Hi m00nie,

    If it says this……….

    Last input 24w4d, output 00:00:01, output hang never

    ……..is it safe to say the port has not been used for 24 weeks and 4 days ? What about the output 00:00:01 ? Does this not mean it HAS been used as it has seen output (so we can’t use it after all) ?

    Your help appreciated.
    Thanks
    Tony

  • Hi m00nie,
    So in the case below, would you say the port has not been used for 24weeks and 4 days ? What about the 00:00:01 ? Does this mean it’s still being used ?…………..

    FastEthernet0/6 is up, line protocol is up
    Last input 24w4d, output 00:00:01, output hang never

    Thanks
    Tony

  • Hi m00nie,

    using your command : show int | i proto.*notconnect|proto.*administratively down|Last in.* [6-9]w|Last in.*[0-9][0-9]w|[0-9]y|disabled|Last input never, output never, output hang never

    My output :

    MYSWITCH#$i proto.*notconnect|proto.*administratively down|Last in.* [6-9]w|Last in.*[0-9][0-9]w|[0-9]y|disabled|Last input never, output never, output hang never
    Last input never, output never, output hang never
    Last input never, output never, output hang never
    GigabitEthernet1/0/1 is down, line protocol is down (notconnect)
    Last input 6w1d, output 6w1d, output hang never
    GigabitEthernet1/0/4 is down, line protocol is down (notconnect)
    Last input never, output 31w6d, output hang never
    GigabitEthernet1/0/6 is down, line protocol is down (notconnect)
    Last input never, output 1y6w, output hang never
    GigabitEthernet1/0/8 is down, line protocol is down (notconnect)
    Last input never, output never, output hang never
    Last input 1y10w, output 00:00:00, output hang never
    GigabitEthernet1/0/12 is down, line protocol is down (notconnect)
    Last input 1y17w, output 5d22h, output hang never
    GigabitEthernet1/0/13 is down, line protocol is down (notconnect)
    Last input 13w2d, output 13w2d, output hang never
    GigabitEthernet1/0/16 is down, line protocol is down (notconnect)
    Last input 1y40w, output 1y6w, output hang never
    GigabitEthernet1/0/18 is down, line protocol is down (notconnect)
    GigabitEthernet1/0/19 is down, line protocol is down (notconnect)
    Last input 12w0d, output 12w0d, output hang never
    GigabitEthernet1/0/24 is down, line protocol is down (notconnect)
    Last input never, output 1y6w, output hang never
    Last input 1y6w, output 00:00:00, output hang never
    Last input 1y11w, output 00:00:00, output hang never
    GigabitEthernet1/0/46 is down, line protocol is down (notconnect)
    Last input 51w3d, output 50w5d, output hang never

    What’s wrong ?

  • Hello,

    Here is an output using command “show int | i proto.*notconnect|proto.*administratively down|Last in.* [6-9]w|Last in.*[0-9][0-9]w|[0-9]y|disabled|Last input never, output never, output hang never” :

    Last input never, output never, output hang never
    Last input never, output never, output hang never
    GigabitEthernet1/0/1 is down, line protocol is down (notconnect)
    Last input never, output 1y23w, output hang never
    GigabitEthernet1/0/2 is down, line protocol is down (notconnect)
    Last input 47w3d, output 47w3d, output hang never
    GigabitEthernet1/0/3 is down, line protocol is down (notconnect)
    Last input 47w3d, output 47w3d, output hang never
    GigabitEthernet1/0/7 is down, line protocol is down (notconnect)
    GigabitEthernet1/0/8 is down, line protocol is down (notconnect)
    Last input 47w2d, output 47w2d, output hang never
    GigabitEthernet1/0/9 is down, line protocol is down (notconnect)
    Last input 47w3d, output 14w5d, output hang never
    GigabitEthernet1/0/10 is down, line protocol is down (notconnect)
    Last input never, output 1y23w, output hang never
    GigabitEthernet1/0/14 is down, line protocol is down (notconnect)
    Last input 47w3d, output 47w2d, output hang never
    GigabitEthernet1/0/15 is down, line protocol is down (notconnect)
    Last input 47w0d, output 47w0d, output hang never
    GigabitEthernet1/0/17 is down, line protocol is down (notconnect)
    Last input never, output 47w1d, output hang never
    GigabitEthernet1/0/22 is down, line protocol is down (notconnect)
    Last input never, output never, output hang never
    Last input 47w3d, output 00:00:01, output hang never
    GigabitEthernet1/0/26 is down, line protocol is down (notconnect)
    Last input never, output never, output hang never
    GigabitEthernet1/0/28 is down, line protocol is down (notconnect)
    Last input never, output never, output hang never
    GigabitEthernet1/0/30 is down, line protocol is down (notconnect)
    Last input never, output never, output hang never
    GigabitEthernet1/0/32 is down, line protocol is down (notconnect)
    Last input never, output never, output hang never
    Last input 51w3d, output 00:00:01, output hang never
    ../..

    What’s wrong on the first two line and also for example Gi1/0/22 -> two lines are displayed. I don’t understand.

    Chris.

Leave a Reply