Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. If you'd prefer to explore, try our test area to get started. And see here for current known issues.

New Member

I would like to build a script in IOS that shuts down ports that are "notconnected"

Is there such  a script.

I have tried:

for xx in `show int status | i notconn`

do

echo $xx

done

and got a list of the interfaces but with the interface line broken up by the spaces;

like so:

953Test#for xx in `show int status | i notconn`
do..done>do
do..done>echo $xx
do..done>done
Gi1/0/9
***
Unused
***
notconnect
10
auto
auto
10/100/1000BaseTX
Gi1/0/10
***
Unused
***
notconnect
10
auto
auto
10/100/1000BaseTX
Gi1/0/12
***
Unused
***
notconnect
10
auto
auto
10/100/1000BaseTX
Gi1/0/13
***
Unused
***

I would like to be able to shut the ports with the list generated.

John Marshall

Everyone's tags (1)
1 REPLY

Hi

Hi

I've done something very quick through my iPad. It works for sure but it could be done in a better way (see below).

On enable mode on the switch, type tclsh to go in scripting mode and then paste this script

puts [open "flash:intshut.tcl" w+] {
set file [open "flash:int.txt" "w+"]
close $file
set output [exec "sh int status | i notconn"]
set file [open "flash:int.txt" "w"]
foreach line [split $output "\n"] {
set interf [lindex $line {0}]
ios_config "interface $interf" "shut" "end"
}
close $file
file delete -force flash:int.txt
}
exit

To execute this script in enable mode :

tclsh flash:intshut.tcl

When you've ran it, you can delete intshut.tcl file in switch flash drive.

Thanks

PS: Please don't forget to rate and mark as correct answer if this solved your issue


Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question
41
Views
0
Helpful
1
Replies