Friday, March 15, 2013

CentOs - Tips and tricks

This post will hold the tips and tricks cheat sheet for things related to CentOs. I will add things to this post as and when I face issues. Please comment here if you would like to add sth to the list or if sth is wrong. Thanks in advance.

I'm using CentOS release 6.3 (Final) version as a base for my VM. I usually get a basic OVA, deploy it to some ESXi host and add my stuff on top of it. That usually means I deploy my web applications, databases, maven repository, etc.
  • When deployed to some host and powered on, no IP address is configured?
         In this version, network service is not started at boot time. Since my OVA is preconfigured my eth0 config looks like this:

DEVICE="eth0"
BOOTPROTO="dhcp"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"

    Look at this link for using other options like static IP or to set up DNS servers: http://linhost.info/2011/12/centos-6-has-no-network-connectivity/

    After configuring eth0, just fire up the following command

service network restart
 
  This would contact dhcp server and get your IP. Then ifconfig should list the interfaces for you with updated IP.

1. This really isn't just related to CentOS but here's to general Linux tips.

To find folder/file recursively, "find $PWD -type d -name 'target"

Thursday, February 2, 2012

Vim Tips and Tricks

VIM ON MAC:

In Macbook, create  a file called $HOME/.vimrc and add the following:

 :syntax on  - To include syntax highlighting in vi as default
:map :w\|!python %  - To save and run python script with just pressing 
:set number - To display line numbers

SCAN AND RUN:


 I had to do performance test on a REST server via SoapUi. This is what I did, in SOAPUI(3.5.1) I created Test suite->Test steps->properties(added the txnId to be unique for subsequent calls)->Groovy script to increment the txnId->Test case which has the sample request->LoadTestcase where I set the delay between requests and total # of requests for n number of threads.

In the server, I added code on server's entry point to print the difference of start and end timestamp. So after the Load Test case is done, I had to extract those timestamps, send it to a script which would calculate the avg time for each request.

The tricky part was how to extract the timestamp difference from the server log. Here's the vi commands to achieve it. In my logs, I had the timestamp in milliseconds like "PERFORMANCE:: 120". So I copy the server log to temp log. Open it via vim editor. In command prompt,

cp server.log temp.log - do not modify the original server log
grep "PERFORMANCE::" temp.log - verify you the test ran successfully
grep -c "PERFORMANCE::" temp.log - count the total number of occurrences
vi temp.log - open the temp log in vi editor
:v/PERFORMANCE:: /d - in esc mode, delete all lines except our performance test line
:%s/^.*PERFORMANCE::\([^"]*\).*$/\1 - in the leftover lines, delete the words and leave the numbers alone
wc -l temp.log - verify the count is still the same, note it down as total#Requests
vi testscript.sh - open file to write script to add the numbers left in temp.log


The file content should be:

sum="0"
for i in `cat $1`;
do
sum=$[$sum + $i];
done
echo "sum = "$sum

chmod +x testscript.sh - to enable execution of the script
./testscript.sh temp.log - to print the sum
then in calculator sum/total#request = avg time taken by the server for each request.

ToNote:
:g/.*/d - to delete all the lines in a file in Vi.

Tuesday, October 25, 2011

Default $PATH value for Mac OS X

When I messed up the PATH variable in my Mac, I found a life saver here.

I'm reposting here the default value of $PATH env variable, in case you screwed up your $PATH.

Just execute, export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

But ideally, remember to do this before you change your PATH variable.

1. In CL, echo $PATH
2. copy the result in file that is already open
3. change your $PATH.
4. If something is wrong, in CL execute "export PATH=savedvalue"

Tuesday, September 13, 2011

Subclipse in Eclipse [MAC]

To install subclipse in Eclipse ide:

Help->Install new software->Add->http://subclipse.tigris.org/update_1.6.x

If you are behind firewall you would get error like this

Unable to connect to repository http://subclipse.tigris.org/update_1.6.x/content.xml Unable to connect to repository http://subclipse.tigris.org/update_1.6.x/content.xml Connection refused

Then do the following,

  1. In Eclipse (go to Preferences > General > Network connections).
  2. Select "Active Provider" as "Manual".
  3. Select HTTP and click edit.
  4. Enter the host and port [proxy host and port get it from office admin]
  5. Select "Reuries Authentication" and enter the username and password.
  6. Repeat Step 1 to 5 for Https.


    Src: http://stackoverflow.com/questions/4598167/eclipse-updates-not-working

Thursday, August 11, 2011

Try Catch Finally

In case of sudden doubts, here are few pointers from specifications:

A try statement with a finally block is executed by first executing the try block. Then there is a choice:


  • If execution of the try block completes normally, then the finally block is executed, and then there is a choice:
    • If the finally block completes normally, then the try statement completes normally.
    • If the finally block completes abruptly for reason S, then the try statement completes abruptly for reason S.
  • If execution of the try block completes abruptly because of a throw of a value V, then there is a choice:
    • If the run-time type of V is assignable to the parameter of any catch clause of the try statement, then the first (leftmost) such catch clause is selected. The value V is assigned to the parameter of the selected catch clause, and the Block of that catch clause is executed. Then there is a choice:
      • If the catch block completes normally, then the finally block is executed. Then there is a choice:
        • If the finally block completes normally, then the try statement completes normally.
        • If the finally block completes abruptly for any reason, then the try statement completes abruptly for the same reason.
      • If the catch block completes abruptly for reason R, then the finally block is executed. Then there is a choice:
        • If the finally block completes normally, then the try statement completes abruptly for reason R.
        • If the finally block completes abruptly for reason S, then the try statement completes abruptly for reason S (and reason R is discarded).
    • If the run-time type of V is not assignable to the parameter of any catch clause of the try statement, then the finally block is executed. Then there is a choice:
      • If the finally block completes normally, then the try statement completes abruptly because of a throw of the value V.
      • If the finally block completes abruptly for reason S, then the try statement completes abruptly for reason S (and the throw of value V is discarded and forgotten).
  • If execution of the try block completes abruptly for any other reason R, then the finally block is executed. Then there is a choice:
    • If the finally block completes normally, then the try statement completes abruptly for reason R.
    • If the finally block completes abruptly for reason S, then the try statement completes abruptly for reason S (and reason R is discarded).



If execution of the try block completes abruptly because of a throw of a value V, then there is a choice:

  • If the run-time type of V is assignable to the Parameter of any catch clause of the try statement, then the first (leftmost) such catch clause is selected. The value V is assigned to the parameter of the selected catch clause, and the Block of that catch clause is executed. If that block completes normally, then the try statement completes normally; if that block completes abruptly for any reason, then the try statement completes abruptly for the same reason.
Src: http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#24134

Thursday, July 28, 2011

SVN : tips and tricks

1. Checkout only a single file from repository without having to download the entire directory.

Sometimes we want to work on only a single file out of 1000's of files in a repository folder. You don't have to download them all. You can do this

svn co --depth empty
cd
svn up
Thanks to source here

2. When you access subversion from Eclipse you will be prompted for username and password. You can select an option to cache the password so you don't have to enter them every time you connect to repository. Suppose if you want to reset the cache and to be prompted for password again, you need to manually delete the file containing the cached password. In Mac OSX, its

~/.subversion/auth/.svn.simple

Now restart the IDE, you will be prompted for password again.


3. If you want to ignore certain files from ever "accidentally" checked in to SVN, do the following. I'm talking about those .settings, .classpath, .project, target, log server.out, depedency-reduced-pom.xml, etc.

  1. Go to ~/.subversion/config file
  2. Find "global-ignores" line. It would be commented by default.
  3. Add this instead "global-ignores = *.classpath *.project *.settings target

The location of config file based on the system:

In Mac/Linux:

~/.subversion/config or /etc/subversion/config

In Window:

%appdata%\subversion\config

Thursday, April 21, 2011

Mac: TcpMon

What: TcpMon is a monitor tool that comes with Apache Axis package and can be downloaded.

Why: If you have a WS client or service that you want to monitor, use TcpMon. Lets say you have written a client for axis2 service as stated here. You also may need to look at the SOAP messages that are sent in the wire.

How:

1. Download TcpMon binary distribution here
2. Execute tcpmon-1.0-bin/build/tcpmon.sh . This will launch the tcpMon console.
3. In 'Admin' tab, enter 'Listen Port#:' Any_port_Number. Set 'Act as: Proxy'. And click Add. New tab as 'Port Any_port_Number' will come up where you can see all traffic.
4. Now you need to set proxy for the web based traffic. In Mac, to System Preferences->Network->Advanced->Proxies->Web proxy. Set 127.0.0.1 and Any_port_Number. Note: you may need to revert back to original settings when you are done with debugging.
5. Run the client in the eclipse. Go to the new tab in tcpmon and you can see the incoming and outgoing SOAP messages for debugging.


Thanks to the source!