As a follow up to my previous post of the above topic, I finally put together a script. I have two scripts, one specifically written for the Internetworkexpert Dynamips topology. The second one can will log into any topology – it takes the name of the .net file as an argument for example
$./tamonet.sh BGPlab.net
Just copy this code, put them in a file with the .sh extension and make then run them from a command line AFTER you have started your routers in GNS3
<———————————————————————————————————————->
#!/bin/bash
#tamonet.sh
# The purpose of this scrip is to launch all running Dynamips router consoles in such a way that all consoles exist
# as tabs in a single terminal windows, rather than the
#default behavior to open multiple windows that just clutters the desktop.
#Script written by Mukom Akong TAMON [mukom to tamon at gmail dot com] …..
#Use and distribute freely …. just give me credit for creating it ok? … ![]()
#Save this with an sh extension, make it executable and then you can run either from
#inside an existing terminal or you press ALT+F2 and then run it. You must pass it the name of the .net file of your current lab
#e.g ./tamonet.sh BGP-Lab01.net
#It is best if you copy the script so it is in the same directory as the directory in which the .net file is.
#Obviously, this script only works for Linux distributions that are using GNOME eg Ubuntu.
PORTS=/tmp/ports
NAMES=/tmp/devicenames
TELNETCMDS=/tmp/telnetcmds
TELNETTABNAME1=/tmp/telnettabname1 #Initial set of command arguments for gnome terminal
TELNETTABNAME2=/tmp/telnettabname2 #Strip away the tab from the commands — just in case
TELNETTABNAME=/tmp/telnettabname #the commands sorted so we have things sequentially
LASTCMD=/tmp/lastcmd.sh
#First delete the files if they exit
rm -f $PORTS
rm -f $NAMES
rm -f $TELNETTABNAME
rm -f $TELNETCMDS
rm -f $TELNETTABNAME1
rm -f $TELNETTABNAME2
rm -f $LASTCMD
#Xtract the ports from .net file and put them into ports file in /tmp
grep -E console $1 | sed s/console\ =\ // | tr -d [] | tr -s ‘[:blank:]‘ >> $PORTS
#Create corresponding file that containts the names
#grep -E ROUTER $1 | sed s/ROUTER\ // | tr -d [] | tr -s ‘[:blank:]‘ >> $NAMES
grep -E ‘\[\[ROUTER' $1 | sed s/ROUTER\ // | tr -d [] | tr -s ‘[:blank:]‘ >> $NAMES
#This block constructs the telnet commands for each router and writes them to $TELNETTABNAME
#inst=0
for i in $( cat $PORTS ); do
# let inst=inst+1
#echo >> $TELNETCMDS “telnet localhost $i -t”
# echo >> $TELNETCMDS “\”telnet localhost $i\” -t”
echo >> $TELNETCMDS “\”telnet localhost” “$i\”" ‘ -t’
done
#Combine the telnet command with the device name on same line
paste $TELNETCMDS $NAMES>>$TELNETTABNAME1
#replace all tabs with a single space.
expand -t 1 $TELNETTABNAME1>>$TELNETTABNAME2
#cat $TELNETTABNAME #| tr ‘\t’ ‘” -t “‘
#Now sort the file
sort $TELNETTABNAME2>>$TELNETTABNAME
#how many lines [routers] in the file?
routers=`wc -l $TELNETTABNAME` #count lines in the file and set result as variable routers.
routers=${routers%$TELNETTABNAME} #Make the routers variable an integer?
echo “There are $routers Routers in this topology”
let “routers = $routers+1″
#declare -i routers #This seems not to serve any useful purpose that I know of
echo “I now start with a router count of $routers”
#This block reads in the commands from a file and assign each line to a dimensioned variable R[x]
{
counter=0
while [ "$counter" -lt "$routers" ]
do
read R[$counter]
let “counter=$counter+1″
done
} < $TELNETTABNAME
#This block just prints out the contents of the dimension – I want to be sure I read the right things into the variables
counter=0
while [ "$counter" -lt "$routers" ]
do
echo ${R[$counter]}
let “counter=$counter+1″
done
#Build the gnome-terminal command and options from the contents of the R[x] dimension
counter=0
let “routers=$routers-2″ #One main window and then the -2 so we cover just the right number of tabbed auxilliary windows
command=”gnome-terminal –window –maximize -e ${R[$counter]}”
#command=”gnome-terminal –window –maximize -e “${R[$counter]}”"
while [ "$counter" -lt "$routers" ]
do
let “counter=$counter+1″
command=”$command –tab -e ${R[$counter]}”
#echo $command
done
echo >>$LASTCMD $command
chmod 777 $LASTCMD
$LASTCMD
<———————————————————————————————————————->
I appreciate any modifications …. and this works for me … so I don’t have to get KDEbase libararies just for konsole4KDE. I hope u enjoy it.
The second script I developed from ideas i saw online …. you really shouldn’t need it cos it only works for the Internetworkexpert .net files.
<———————————————————————————————————————->
#!/bin/bash
#This script enables me login to all routers in the Internetworkexpert Dynamips standard lab
#in such a way that all consoles exist as tabs in a single terminal windows, rather than the
#default behavior to open multiple windows that just clutters the desktop.
#Script written by Mukom Akong TAMON [mukom to tamon at gmail dot com] …..
#Use and distribute freely …. just give me credit for creating it ok? … ![]()
#Save this with an sh extension, make it executable and then you can run either from
#inside an existing terminal or you press ALT+F2 and then run it.
#Obviously, this script only works for Linux distributions that are using GNOME eg Ubuntu.
# — start multi-tabbed telnet session
r1=”telnet localhost 2001″
r2=”telnet localhost 2002″
r3=”telnet localhost 2003″
r4=”telnet localhost 2004″
r5=”telnet localhost 2005″
r6=”telnet localhost 2006″
sw1=”telnet localhost 2007″
sw2=”telnet localhost 2008″
sw3=”telnet localhost 2009″
sw4=”telnet localhost 2010″
bb1=”telnet localhost 2011″
bb2=”telnet localhost 2012″
bb3=”telnet localhost 2013″
gnome-terminal \
–window –maximize -e “$r1″ -t R1 \
–tab -e “$r2″ -t R2 \
–tab -e “$r3″ -t R3 \
–tab -e “$r4″ -t R4 \
–tab -e “$r5″ -t R5 \
–tab -e “$r6″ -t R6 \
–tab -e “$sw1″ -t SW1 \
–tab -e “$sw2″ -t SW2 \
–tab -e “$sw3″ -t SW3 \
–tab -e “$sw4″ -t SW4 \
–tab -e “$bb1″ -t BB1 \
–tab -e “$bb2″ -t BB2 \
–tab -e “$bb3″ -t BB3
<———————————————————————————————————————->
May 12, 2009 at 8:59 pm |
Hi there!
Nice scripts, but I have something to comment.
Maybe it’s only for me (Ubuntu 9.04) but the secondary script did not work as you provide it above.
I had to modify from -tab to –tab, -maximize to –maximize and also the same for -window to –window.
Thanks and keep on the good work!
May 19, 2009 at 3:56 pm |
Thanks Calin, am glad u find it useful. I myself can’t do without it
June 22, 2009 at 4:52 pm |
I am running U8.10. I am trying the first script. I am getting the following error. I am a newbie for the Linux.
tango@tango-laptop:~$ /home/tango/Public/CCIE/EnableTab.sh Lab_2 EIGRP.net
bash: /home/tango/Public/CCIE/EnableTab.sh: Permission denied
I have checked the permission. I have Read and Write permission to the folder and files. I donot have files (like $ports, etc). I have also tried to rem out that portion.
Any help will be much appreciated.