TestLab Scripts
I wrote a couple of scripts for the testlab this week and figured I would share them. You can download them here. These could be modified for a GNS3 lab setup easily as well. Not wanting to reinvent the wheel I googled around and started hacking another script. It started off with something like this:
# Usage: $0 [command]
pgrep -u "$USER" gnome-terminal | grep -qvx "$$"
if [ "$?" -eq 0 ]; then
WID=`xdotool search --class "gnome-terminal" | head -1`
xdotool windowactivate $WID
#xdotool key ctrl+shift+t
xdotool key ctrl+t
But gnome-terminal sets the environmental variable WINDOWID so I began by changing it to:
# Usage: $0 [command]
xdotool windowactivate $WINDOWID
xdotool key ctrl+t
But then I read the gnome-terminal manpage to see what other environmental variables it set and decided all the xdotool commands were too much for what I needed. So I simplified into two main scripts, one to handle the gnome-terminal interactions and one to handle the router interactions.
# 2010-06-14 Jud Bishop
# tlr
# This script opens a single gnome-terminal tab and log into a router in
# the testlab.
if [ $# -ne 1 ]
then
echo -e "Usage: ${0} router_id\n tlr R1\n"
exit 1
fi
gnome-terminal --tab -e "tle ${1}" -t "${1}"
The expect script to handle the interaction with the 2511-RJ getting logged into the router.
# 2010-06-14 Jud Bishop
# tle
# A short script to handle logging into a router in the lab.
set host "testlab.chainringcircus.org"
set pass "CHANGEME"
##############################
# Should not need any more changes.
set router [lindex $argv 0]
spawn telnet $host
expect "Password:"
send "$pass\r"
expect "testlab>"
send "telnet $router\r"
sleep 1
send "\r"
sleep 1
send "\r"
interact
exit
And finally the script that logs into every router in the lab, renaming the tab title to match the router name.
# 2010-06-14 Jud Bishop
# tl
# This script fires up gnome-terminal with a bunch of tabs each executing
# the tle script and naming the tab with the router name.
gnome-terminal --tab -e "tle R1" -t "R1" \
--tab -e "tle R2" -t "R2" \
--tab -e "tle R3" -t "R3" \
--tab -e "tle R4" -t "R4" \
--tab -e "tle R5" -t "R5" \
--tab -e "tle R6" -t "R6" \
--tab -e "tle R7" -t "R7" \
--tab -e "tle R8" -t "R8" \
--tab -e "tle R9" -t "R9" \
--tab -e "tle Cat1" -t "Cat1" \
--tab -e "tle Cat2" -t "Cat2" \
--tab -e "tle Cat3" -t "Cat3" \
--tab -e "tle Cat4" -t "Cat4" \
--tab -e "tle BB1" -t "BB1" \
--tab -e "tle BB2" -t "BB2" \
--tab -e "tle BB3" -t "BB3"
Alright! i am very interested in this. Im working on my CCIP right now and my main lab is 18+ routers. Dont need that many but i like the challange :), plus i find MPLS and BGP very interesting and cant get enough of it right now
Ill be playing around with this very soon!
Thanks Jud
Glad to hear it will help. I should mention that these scripts actually log me into a 2511-RJ, and from there into the console of the router.
Hope that helps. Sounds like a nice lab with 18+ routers.
Jud