Wednesday, September 14, 2011

Most useful vi editor ( vim editor ) commands

Backspace and arrow keys behave differently in vi editor. Better alternative is vim editor.
Install vim editor as below
$sudo apt-get install vim

Alright, before we start, vim editor has two modes.
  1. Command Mode: This is the default mode. When vim editor is first started, it enters in this mode. Command mode is useful for tasks like copying, deleting, seaching etc..
  2. Insert Mode: This is the mode for entering text 
Since vim is in command mode initially, to get to insert mode, all you need to do is, hit key i 
To get back to command mode from insert mode, hit key Esc

Note: there are other keys that can change the editor from command mode to insert mode but to keep this post simple, I am not going to discuss that

Now to the commands

Open File
$vim sample_file.txt

Change to insert mode by hitting the key i and type few lines so that we can use some other commands.
Now, come back to command mode by hitting Esc


Save file
:wq

Quit modified file without saving
:q!

Quit unmodified file
:q

Great. Now you can open a file, type some text, save and exit.
Lets open the file again with vim editor and try some more commands. I am assuming that you typed in atleast 10 lines.

Copy a line
yy

Copy 5 lines
5yy (you get the idea)

paste the copied line/s from buffer
p

delete a line
dd

delete 5 lines (home work :) )

Greate now you can copy n paste too. saves lot of time, isn't it. Now the most useful command

Search
:/word (after hitting enter, use n to go to next match) 

Case-Insensitive Search
:/cword

Go to the end of file
:$

That's it. These are the basic commands that you need to know for doing some simple things with vim editor.





Friday, September 2, 2011

jps can not detect the tomcat process? not a problem!

Before going any further, first thing you need to do is to check and see what version of jdk is being used by tomcat. Is it Java 6 Update 23 or Java 6 Update 24? you are at the right place

Why this problem?
some bug in jvm. I would not go into details. if you are interested please look at below links

https://issues.apache.org/bugzilla/show_bug.cgi?id=50518
http://stackoverflow.com/questions/6287926/jps-not-showing-tomcat-process

 How to fix it?

Solution 1
Use any other version than the above mentioned ones

Solution 2
If, for some reason, you have to keep the same version. do below.
  1. Find where tomcat is saving the monitoring related data.
    This normally gets saved at $java.io.tmpdir. Easy way to figure out is to search for directories starting with hsperf* on your machine.
    some thing like below would work on linux.
    $find / -name hsperf*
  2. lets say it is found at /tmp/tomcat6_tmp/hsperfdata_root
    $jps -J-Djava.io.tmpdir= /tmp/tomcat6_tmp
  3. For any other jvm monitoring tool to work, the tool needs to know where the above found file is. for example for jstat to give details about your tomcat process (lets say processid/vmid is 12345..)
    $jstat -gc 12345 -J-Djava.io.tmpdir=/tmp/tomcat6_tmp


Happy monitoring...

Followers