Even More TestLab Scripts

I doubt many home labs match hardware exactly with whatever the vendor has recommended. As a result most of us must script around or manually edit vendor configuration files. Here are some of my earlier scripts that I have shared that have been updated and a couple of new ones.

tl-checklist — TestLab CheckList
So that others will be able to understand the process, I have decided to walk you through the use of these scripts. The first one started out as a checklist of changes to make to each different device for every lab, but that was quickly replaced with a script. Funny thing about scripts like this, it should have probably been written in Perl but I did not expect it to grow to this size.

Each lab has its own directory of configuration files and this script works its way through each configuration file making changes as it goes. Here is an output of the usage example.

Usage: tl-checklist LAB-X
   tl-checklist LAB-1

I have tried to make the script idiot proof for my own sake. The first thing it does is make a copy of the directory so that a backup of the original exists. Then it puts a marker in the directory so that the script knows whether it has updated those configuration files before. If you have run the script on that directory it will fail gracefully.

if [[ $# -ne 1 ]]
        echo -e "Usage: ${0} LAB-X\n ${0} LAB-1\n"
        exit 1
elif [[ -e "/tftpboot/VOL-1/${LAB}/check-list" ]]
	echo -e "\n${0} has been run on this directory before."
	echo -e "Please remove /tftpboot/VOL-1/${LAB}/check-list."
	echo -e "And run the script again."
	exit 1
	touch "/tftpboot/VOL-1/${LAB}/check-list"

	if [[ ! (-d /tftpboot/VOL-1/${LAB}.0) ]]
		cp -r "/tftpboot/VOL-1/${LAB}" "/tftpboot/VOL-1/${LAB}.0"

Finally it loops through each device and makes changes that are need for each device to work properly with the other scripts and for the configuration to actually match my hardware connections.

for I in R1 R2 R4 R5 R6 R7 R9 Cat1 Cat2 Cat3 Cat4 BB1 BB2 BB3
	# The $$ on the end is just in case you run this script multiple times
	# the oldest file in an ls -tlr will be the true original.
	if [ -e $CONF ] 
		mv $CONF $SAVE

		echo $I
		case $I in 
		R1 )
			sed 's/^boot.*//g
			s/clock rate 2000000/clock rate 128000/g' $SAVE >$CONF
The rest is removed for brevity.

The long term reader will recognize that this script dovetails nicely with the previous testlab scripts. For instance, the backbone routers and catalyst switches are renamed to match the hostname expected in the upgrade scripts. It also uses the same command line switches so that it integrates with some of the earlier scripts.

tl-update-router — TestLab Update Router
The next script draws on tlue (testlab update expect) to go through and upgrade any number of switches or routers.

Usage: tl-update-router -l LAB-X -r Rx [dtn]
 -r Rx is required.
     If -r equals all, then the entire lab will have the specified configuration loaded.
     If -r equals routers, then the routers in the lab will have the specified configuration loaded.
     If -r equals switches, the switches in the lab will have the specified configuration loaded.
 -d load flash:def first.
 -t load flash:new from tftp
 -l LAB-X is required if tftp or new is specified.
 -n run configure replace flash:new
 -c configure the router from the console
tl-update-router -l LAB-1 -r all -dc

The final line of the usage example is how I normally run this script. This particular example tells the script to upgrade all of the switches and routers to the initial configuration for LAB-1.

tl-update-router -l LAB-1 -r all -dc

In doing so it will first run a configure replace command loading the flash:def file, then it will load the LAB-1 configuration file from the console. The reason I moved from configure replace of a tftp copied file onto flash was because I was not getting consistent results. If, however, I went back and pasted the switch or router configuration over the console input the configuration would take and as a result I just switched to having the script input the configuration over the console session.

tlue — TestLab Update Expect
The tlue script handle the interaction of the switches and routers through expect. A friend gave me a more thorough example but it seemed overkill for my purposes. By this time I know where I usually have problems, the serial interface of R2, but other than that this script works well.

This procedure is the one that sends the configuration over the console cable.

This entry was posted in Code, Routing. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s