cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1327
Views
0
Helpful
1
Replies

IOS shell to run commands to only "switchport mode access" interfaces

hrodriguez231
Level 1
Level 1

Hi there!

So far at my workplace I'm using Rancid for backups and to push global commands to groups of switches or to all the cisco switches, but that's what so far I know about Rancid.

Is there any way that you guys can share the different Scripts that probably you already have to push certain commands to only my access ports and not my trunk ports?

example: Let's say I want to run "ip dhcp snooping limit rate 100" to only those interfaces, do you have an bash script that does that, or if you run the script will connect to the switch one by one/read the config of each one/save it to the clipboard but only the mode access interfaces/then point to an script where you can run the command to only those interfaces?? That's one of the issues I'm facing right now with the amount of switches I take care. The other problem is almost the same, I'm looking for a script that read ALL the interfaces of the switch and deploy the command to all the interfaces. example: "load-interval 30" Thank you in advance and looking forward to know what do you guys have in place to accomplish this.

I would like to know if there is a way using IOS shell to accomplish this, where by running on the terminal shell it will print all the "switchport mode access" interfaces and run commands to only those interfaces?

Please I only know the basics of ios shell and scripting so if you can post the entire script will be much appreciated.

FYI I'm only using 2960-S and 2960-X.

Thanks.

1 Reply 1

Dan Frey
Cisco Employee
Cisco Employee

Here is a script that can be pasted into the tcl shell of the device that will apply the same command to non-trunk ports.

tclsh

set ports [exec sh int status | exclude trunk]

foreach line [split $ports "\n"] {

  if [regexp {^([A-Za-z0-9]+\/[0-9\/]+)\s+} $line match port] {

  ios_config "interface $port" "ip dhcp snooping limit rate 100"

  }

}

Review Cisco Networking for a $25 gift card