Open GNS3 Router Consoles in Multiple Tabs in a Single Window [GNOME]

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

# 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=/Users/mukom/tmp/ports
NAMES=/Users/mukom/tmp/devicenames
TELNETCMDS=/Users/mukom/tmp/telnetcmds
TELNETTABNAME1=/Users/mukom/tmp/telnettabname1	#Initial set of command arguments for gnome terminal
TELNETTABNAME2=/Users/mukom/tmp/telnettabname2	#Strip away the tab from the commands -- just in case
TELNETTABNAME=/Users/mukom/tmp/telnettabname		#the commands sorted so we have things sequentially
LASTCMD=/Users/mukom/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]}"
while [ "$counter" -lt "$routers" ]
	do
		let "counter=$counter+1"
		command="$command --tab -e ${R[$counter]}"
		#echo $command
	done
echo >>$LASTCMD $command
chmod 777 $LASTCMD
#I can delete these files now, since I no longer need them --- just house cleaning
rm -f  $PORTS
rm -f  $NAMES
rm -f $TELNETTABNAME
rm -f $TELNETCMDS
rm -f $TELNETTABNAME1
rm -f $TELNETTABNAME2
$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.

Making GNS3 Routers Open in Tabs in Ubuntu

If you use GNS3 network emulator with a significant number or routers, each usually opens up in its own terminal window which just makes your workspace a mess.

While I know I can install konsole-for-KDE4 in Ubuntu to sort out the clutter, I don´t like to have to download more than 30MB extra software [KDE base libraries and other dependencies] so I opt to create this scrip which I can easily edit.

Just download the script, make it executable and after running the your lab from GNS3, rather than use the toolbar button to log into to all consoles, instead press ALT+F2 and type in the path to the script [do remember to make it executable] and voila!!!

On Vista, I use Teraterm for my console and so the above problem does not exist. If you use the default Vista command prompt you will run into the same problem. I read a nice GNS3 tutorial that suggested a free Windows utililty called Wintabber to tame those multiple windows.

If your Linux distribution uses KDE, install konsole-for-KDE4 and use it as your terminal program in GNS3 to get the same results.

I am working on some scripts to automate the process for Ubuntu and gnome-terminal — I don’t want to install all the KDE base packages just to get konsole-for-KDE … will post the scripts [bash] when I am done.

Fixing the Menu Editor in Ubuntu

I had my shiny new 64-bit Ubuntu 8.10 up and running and then decided to do some arrangements on my menus  and behold … I would right-click on the Ubuntu icon and select Edit Menus but nothing would happen. Even a trip to Preferences->Main Menu was unresponsive. Well, I know that the program that does menu editing in Gnome is called alacarte, so I decided to run alacarte from the command line and that is where I discovered the source of the problems. U see during setup, when u choose you language and country, Ubuntu setup uses them to decide your locale, so in my case my locale turned out to be en_NG (Nigerian English) and that was just not an acceptable locale to Python (the programming language in which alacarte is written). So how do you fix it? … simple, just set your locale to one of the mainstream (whoever decides that, I don´t know) ones, in my case, since we actually use British English.

Go to Settings.Adminstration.Language Support. In the Default Language section, choose English UK, or English US.
I suspect that French France, Spannish Spain etc would work for the other major languages.

With those settings, just log off and log back in (or better still just reboot) and your menu editing woes will be over.

For the curious, with my choice, my locale became en_GB (or is it en_UK?) which was an acceptable locale to Python.