Print this Post

Bulk enable PIM via TCL

I’ve been working on doing some multicast labs lately and am constantly resetting my lab devices to their default configs and starting from scratch. As many of us know, to enable PIM on all of your interfaces you must go into each interface and enable it manually. There is no default command to enable PIM on all interfaces. We know PIM should be enabled 1 to 1 with interfaces involved in routing making this a boon. With that in mind, and the fact that I am rather comfortable with the concept of needing PIM on the interfaces, and likely speak and type this command in my sleep, I decided to make it easier and modify a previous TCL script I had written to enable PIM on every interface that has an IP address assigned to it. With the great “Send to Chat” feature of SecureCRT I can do this across my entire topology on one fell swoop. In a real world environment, you could use a tool like Solarwinds to push this out to your devices.

The script is outlined below. I will start by going over the variables you will want to change based on your environment and follow with that the script itself it actually doing.

  1. The first variable is the  file path and/or name (lines: 3,6,11)
    1. Change the path to a location available on your router/switch. In my case the version I was using left me only with nvram: In many production systems it may be flash:/
    2. The file name is arbitrary but must be unique to the file path
  2. The second variable is the version of PIM you want to run (line 9)
    1. In my case I was issuing the ip pim sparse-mode command

As far as how the script works: When I was using this script in its previous form for a different task I found an oddity that seemed to work better when I closed and reopened the file. With that in mind, here is the synopsis.

The script starts out by running an executive command which is in this case show ip interface brief | exclude unassigned. This filters to only the interfaces with an IP address assigned and is placed in a variable. Another variable is created containing the text file name and path. At this point, the output of the command is placed into the text file via the two variables and the text file is closed.

We now reopen the file and place the contents into a loop. For reach new line in the file I grab the first 16 characters (indicated by 0 – 15 on line 8) and put those characters into a variable called interface. Now the command to enter interface config mode is issued with the variable $interface defining the interface Module #/#. Under that mode the PIM command is entered. Rinse and repeat for reach line in the file until the loop is complete. At this point I close the file and delete it as it is no longer need.

This specific instance is built of Ethernet#/#.### character length. If your environment is using FastEtherent, Serial, GigabitEthernet, longer sub interfaces, or long #/#/# module you may need to increase the number of characters you grab. Again, this is on line 8 and indicated by 0 (the starting character) and 15 (the last character). This is based on the output of the show ip interface brief command.


Matt Ouellette is a certified information technology professional residing in Southwest Michigan. His technology findings and advice can be found on his PacketPilot blog. Mr. Ouellette spent 4 years as an I.T. Technician before stepping into a Network Engineer role at Bronson Health Group. Since completing his Associates Degree in Network Administration Matt has taken a head on approach to career enrichment through obtaining credentials such as CCNP, CCNA Voice, MCSA: Server 2008, and VCP5. This passion for continued learning allows him to deliver up to date quality technical solutions.

Permanent link to this article: http://www.packetpilot.com/bulk-enable-pim-via-tcl/