cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4499
Views
0
Helpful
11
Replies
Highlighted
Beginner

TCL script for shutting down various ports

Hi all, I have about 20 different interfaces on multiple 6509 switches that I want to shut down.  How would I write a TCL script that I could edit for each switch that has different interfaces that need shut down? 

I've seen some good examples in other posts, but the best one I found looked like it would be a lot of work to change the interfaces that need shut down in each script.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Hall of Fame Cisco Employee

The script's ios_config line would change to:

ios_config "int range $ports" "shut" "switchport access vlan 44" "end"

The script would be invoked as:

tclsh disk0:shut_ports.tcl "Gi1/15 , Gi1/34 , Gi1/35 , Gi2/27 , Gi2/40"

View solution in original post

11 REPLIES 11
Highlighted
Hall of Fame Cisco Employee

You could do a very simple tclsh script for this.  The script itself would be:

###

set ports [lindex argv 0]

ios_config "int range $ports" "shut" "end"

###

Then to call it:

Switch#tclsh diak0:/shut_ports.tcl "Gi1/1 - 8"

Where the quoted argument is something that would be supported by the IOS "range" syntax.  This should be fairly flexible and work for all of your 6500s.

Highlighted

Thanks so much, I'm not very well versed in TCL scripting but I see how that would work.  Just as an example, how would the script look if I had the following interfaces I needed shut down? 

Gi1/15

Gi1/34

Gi1/35

Gi2/27

Gi2/40

Would it also be possible to simultaniously move these interfaces into another vlan (I want to move them into a dead VLAN while I'm at it).  For the sake of the example lets say the dead vlan is 44.

Highlighted
Hall of Fame Cisco Employee

The script's ios_config line would change to:

ios_config "int range $ports" "shut" "switchport access vlan 44" "end"

The script would be invoked as:

tclsh disk0:shut_ports.tcl "Gi1/15 , Gi1/34 , Gi1/35 , Gi2/27 , Gi2/40"

View solution in original post

Highlighted

I'm having some trouble getting this to work so let me just give a quick rundown of what I'm doing to make sure I'm not missing anything:

I'm testing this on a lab router just because I don't want to try my first TCL script on production equipment

I'm using a 2611XM router with IOS image: c2600-adventerprisek9-mz.124-15.T14.bin

My 3550 switches don't appear to accept the tclsh command, so I can only really test on my routers.

I copied the following text into notepad and saved as shut_ports.tcl then TFTP'd this to the 2611XM router:

     set ports [lindex argv 0]

     ios_config "int range $ports" "shut" "end"

I then TFTP's this .tcl file to the 2611XM router and tried to invoke the script by entering:

CME_Router#

CME_Router#sh ip int bri

Interface                  IP-Address      OK? Method Status                Protocol

FastEthernet0/0            unassigned      YES NVRAM  up                    up     

FastEthernet0/0.1          172.16.1.1      YES NVRAM  up                    up     

FastEthernet0/0.2          172.16.2.1      YES NVRAM  up                    up     

Serial0/0                  unassigned      YES NVRAM  down                  down   

FastEthernet0/1            10.50.20.125    YES NVRAM  up                    down   

Loopback1                  unassigned      YES unset  up                    up     

Loopback2                  unassigned      YES unset  up                    up     

CME_Router#

CME_Router#

CME_Router#tclsh flash:shut_ports.tcl "Fa0/0"

CME_Router#

*Mar 13 13:03:01.427: %SYS-5-CONFIG_I: Configured from console by console

CME_Router#

CME_Router#tclsh flash:shut_ports.tcl "Fa0/1"

CME_Router#

*Mar 13 13:03:08.667: %SYS-5-CONFIG_I: Configured from console by console

CME_Router#

CME_Router#sh ip int bri

Interface                  IP-Address      OK? Method Status                Protocol

FastEthernet0/0            unassigned      YES NVRAM  up                    up     

FastEthernet0/0.1          172.16.1.1      YES NVRAM  up                    up     

FastEthernet0/0.2          172.16.2.1      YES NVRAM  up                    up     

Serial0/0                  unassigned      YES NVRAM  down                  down   

FastEthernet0/1            10.50.20.125    YES NVRAM  up                    down   

Loopback1                  unassigned      YES unset  up                    up     

Loopback2                  unassigned      YES unset  up                    up     

CME_Router#

CME_Router#

I tried invoking on different interfaces but they stayed up without any change.  I don't know if this has to do with using the 2611XM router or if I'm just not doing this correctly.  The above system message appears to confirm the script is at least entering/exiting configuration mode, but the interfaces aren't being shut down.

Highlighted
Beginner

ahh I figured out the problem.  I needed to add a $ symbol before argv 0  I just updated the tcl file and it now works perfectly!

Thanks a ton, I'd still be reading pages of TCL tutorials if I were to try to figure this on my own!

Highlighted

Looks like I got a bit ahead of myself because I can only go one port at a time.  Is the range command correct in this statement?  I can only get the script to work if I remove the range command.  The switch supports the interface range command if I type it in, but for some reason it doesn't like it in this script.  Below is the script I'm using:

set ports [lindex $argv 0]

ios_config "int range $ports" "shut" "switchport access vlan 44" "end"

Highlighted
Hall of Fame Cisco Employee

How are you calling the script?  The range argument is needed for simplicity, but it requires you to specify the list of ports very specifically.  Can you confirm the range syntax you're using would work manually?

Highlighted

Here is an output of a session I just did.  Both ports are currently up, but the script doesn't shut them down.  I can enter the range command and shut them both down at once so I know that works, but for some reason the range command isn't working from the script.  I used the above script sent via tftp.

6509_switch#sh int g1/8 status

Port         Name               Status       Vlan       Duplex  Speed Type

Gi1/8                           notconnect   100          auto   auto 10/100/1000BaseT

6509_switch#sh int g1/9 status

Port         Name               Status       Vlan       Duplex  Speed Type

Gi1/9                           notconnect   100          auto   auto 10/100/1000BaseT

6509_switch#tclsh tftp://172.16.1.11/testshut4.tcl "Gi1/8 , Gi1/9"

Loading testshut4.tcl from 172.16.1.11 (via Vlan50): !

[OK - 101 bytes]

6509_switch#sh int g1/8 status                                   

Port         Name               Status       Vlan       Duplex  Speed Type

Gi1/8                           notconnect   100          auto   auto 10/100/1000BaseT

6509_switch#sh int g1/9 status                                   

Port         Name               Status       Vlan       Duplex  Speed Type

Gi1/9                           notconnect   100          auto   auto 10/100/1000BaseT

6509_switch#

6509_switch#config t

Enter configuration commands, one per line.  End with CNTL/Z.

6509_switch(config)#int range gi1/8 , gi1/9

6509_switch(config-if-range)#shut

6509_switch(config-if-range)#do sh int g1/8 status 

Port         Name               Status       Vlan       Duplex  Speed Type

Gi1/8                           disabled     100          auto   auto 10/100/1000BaseT

6509_switch(config-if-range)#do sh int g1/9 status

Port         Name               Status       Vlan       Duplex  Speed Type

Gi1/9                           disabled     100          auto   auto 10/100/1000BaseT

6509_switch(config-if-range)#

Highlighted
Hall of Fame Cisco Employee

Have you tried without the switchport access vlan 44 in your script?  I tested a simple range script locally with a port description being set, and it works.

Highlighted

Just tried again with the below script, and it still won't work, even if I just invoke it for a single interface.

set ports [lindex $argv 0]

ios_config "int range $ports" "shut" "end"

I also tried one with interface fully typed out, but with the same results.  Not sure why the scripts with range added don't seem to work

Highlighted
Hall of Fame Cisco Employee

Add a puts statement as line two:

puts "Args is '$ports'"

I tested on another switch here, and it works to shut ports down.  Have you confirmed that this switch does work with one port without "range" using the Tcl script?

Content for Community-Ad