Thursday, 14 February 2013

bash unexpected end of file problem

bash unexpected end of file problem


Other day I was working for my research in Ubuntu and I needed to automate a process. I decide to write a bash script but my while loop was not working at all. Any condition and loop I wrote, it gave me a unexpected end of file error. I try to google for more than an hour but nothing was helpful. Even though my syntax seems to be correct but the terminal was giving me same error again and again. I was not able to figure out what was causing the error but, finally I was able to solve it.

There are several reasons for throwing this error when working with the bash script and mostly its due to syntax error. But, sometimes even  though every syntax is correct, you may still get this error and those times are really frustrating. It took me more than 2 hours to figure out the problem.

Cause:
I figure our the cause of this problem. It is due to the line ending used by various OS. I figure out that when we save our file in gedit (ubuntu), it has 3 line ending options as,
1. Unix/linux
2. Mac
3. Windows.



By default, windows is selected as line ending, and if its the case then how much you write the correct syntax, bash will not run and give you the unexpected end of file error.



Solution:
Just use the line ending as unix/linux and your bash script should work well this time. I hope this simple information is helpful.



Thank you and have a nice day...

Sunday, 11 November 2012

How to Install and Configure NS-2 with Eclipse in Linux

Running NS-2

Ns-2 can be run both in windows or Linux platform.

Best option

  • Use Linux 

How to run NS-2 under Windows?

  • Using Cygwin (not recommended)
  • Using Virtual machine
    • Vmware station (not free)
    • WM player (free and recommended)
    • Virtualbox (free)
  • others



Installation Procedures for NS-2 (ns-allinone-2.34)


Step 1: Download

download the latest ns2 copy . their are two methods to do that
1. go to terminal and type
wget http://nchc.dl.sourceforge.net/sourceforge/nsnam/ns-allinone-2.34.tar.gz
2. u can download it from here
Step 2: Extract
extract the tar file in home directory  i.e. /home/username
OR
try this in terminal
tar -xzvf ns-allinone-2.34.tar.gz
step 3 :install
just type following commands

cd ns-allinone-2.34
sudo apt-get install build-essential autoconf automake libxmu-dev
./install
Step 4: Set environment variables
$ gedit ~/.bashrc
Add the following lines to the end of the file. Remember replace “/your/path” by the folder where you have stored extracted the ns-2 file

# LD_LIBRARY_PATH
OTCL_LIB=/your/path/ns-allinone-2.34/otcl-1.13
NS2_LIB=/your/path/ns-allinone-2.34/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB

# TCL_LIBRARY
TCL_LIB=/your/path/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH
XGRAPH=/your/path/ns-allinone-2.34/bin:/your/path/ns-allinone-2.34/tcl8.4.18/unix:/your/path/ns-allinone-2.34/tk8.4.18/unix
NS=/your/path/ns-allinone-2.34/ns-2.34/
NAM=/your/path/ns-allinone-2.34/nam-1.14/
PATH=$PATH:$XGRAPH:$NS:$NAM

Ensure that it immediately takes effect:
$ source ~/.bashrc

Note: the previous step is important; else you cannot successfully run ns-2.
(Alternatively, you may have to restart your X-windows, that is logout, and then login, or restart your computer.)
Now, the installation has been completed. Try:
$ ns
The “%” symbol appears on the screen. Type “exit” to quit.

Validation (optional)

To run the ns validation suite:
$ cd ns-2.34
$ ./validate