Auto Reloading your router with TCL

So you would like to Auto reload all the 6 of 10 routers in your rack and maybe you would like to clear the config at the same time?

A ‘Send *’ from your Access-Server would apply to all connected routers and switches . Not cool, since you do not want to reload the backbone routers and the frame-switch’s config every time. And quite frankly erasing and reloading one router at a time is just to much work and wastes time. Studying for you CCIE? Then you will know you don’t have time to waste.

So how to go about this? You could create 2 EEM applets in every initial config before loading the routers as follow:

event manager applet writeerase
event none
action 1.0 cli command "write erase"
event manager applet forcereload
event none
action 1.0 reload

Then from your access-server, you could run the following, causing only the routers that have the applets loaded interpret the send commands:

Send *
Enter message, end with CTRL/Z; abort with CTRL/C:
event manager run writeerase
event manager run forcereload
Send message? [confirm]

But really, this is still TOO MUCH work. Updating each initial config of every lab. There is always a “lazier” way to do stuff.
What we need is a file saved on the router that is not affected when the config is erased. Hmmm…. a small TCL-script could do that.

First before writing the script, we need get the commands in the correct order for execution and see if there is any responses required. An this is where the tricky part comes in.

If the command ‘write erase’ is used on the router, the router requires user-input to confirm that!

Router#write erase
Erasing the nvram filesystem will remove all configuration files! Continue? [confirm]

Hmm, this would cause your scripts to pause/hang, waiting for input. For that you will need to issue the TCL-command ‘type ahead’ to insert a {RETURN} response to the command ‘write erase’. In TCL language that would be a ‘\r’.
Then we also need to save the script to Flash memory on each router. All and all, the short little script would look something like this:

puts [open "flash:wiped.tcl" w+] {
puts [ exec "write" ]
typeahead "\r"
puts [ exec "write erase" ]
typeahead "\r"
puts [ exec "reload" ]

Install the above script on all the routers that you want to erase-and-reload from you access-server. Once done and you want to perform the awesomeness do this from you Access-Server:

Send *
Enter message, end with CTRL/Z; abort with CTRL/C:
tclsh wiped.tcl
Send message? [confirm]


One thought on “Auto Reloading your router with TCL

Please leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s