Thursday, 15 November 2012

Generating Heap Dump In Linux/Jboss/Sun JVM

jmap -dump:live,file=<location to save the file>/<filename>.hprof <PID>

jmap -F -dump:live,file=/home/heapdump/heapdump.hprof 2323
 
For 64 bit JVM (should take default but some times if you have multiple JAVA in the same box), use below option:-                                                                                                                   

jmap -J-d64 -dump:live,file=<location to save the file>/<filename>.hprof <PID>



NOTE: you have to run "jmap" from your <JAVA_HOME/bin>

Find Process associated with Port


In Linux:-
----------
netstat -tulpn
----------
In AIX:-
------------------
#netstat -Aan | grep Port_Number
==>Above command will Display the process who is holding the socket then use below command to get the Process ID.

#rmsock <Address_of_PCB> tcpcb
<Address_of_PCB> => is the output of previous command
-------------------                                                                                                                

Script to find Default JMS Queue Details in WAS

To get the default JMS Queue details in WAS (Web sphere Application Server), below “jacl” script can be used.
set perfName [$AdminControl queryNames WebSphere:type=SIBQueuePoint,name=QUEUE_NAME,process=server1,*"]

set identifier [$AdminControl getAttribute $perfName identifier]

puts [$AdminControl getAttributes $perfName]
Let say we have saved above script in file called “test.jacl”, then it can be executed from WAS_HOME/bin as below:-
./wsadmin.sh -lang jacl -user <user-id> -password <password> -conntype SOAP -port <SOAP-Port> -f test.jacl

Output Will be like:-

WASX7209I: Connected to process "server1" on node <NODE-NAME> using SOAP connector;  The type of process is: UnManagedProcess
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv variable: "[QUEUE_NAME]"

{depth 0} {state ACTIVE} {id 94828E41C96C098B9A781FF9_QUEUE_189} {identifier QUEUE_NAME} {highMessageThreshold 50000} {sendAllowed true}

Perl script to KILL process with given name in Windows

Perl script to KILL process with given name in Windows.
This script is useful as part of any automated process that runs in Windows in order to kill a process with given name.

$|++; # force auto flush of output buffer
system("WMIC /OUTPUT:C:\\log.txt path win32_process get Processid,Commandline");
$infile1="C:/log.txt";
open(IN1,"<:encoding(UTF-16LE)","$infile1");
$profilename="<PROCESS_NAME>";
while(<IN1>)
{
            next if (/^(\s)*$/);#skip blank lines
            s/(\s)+$//g; #Removing white space at the end of line.
            if (/$profilename/)
            {
            print "$1\n" if (m/(\d+)$/);
            system("taskkill /F /PID $1");
            }
}
close(IN1);

Using grep (traditional UNIX way) to recover files - Deleted by rm -rf


Using grep (traditional UNIX way) to recover files

Use following grep syntax:
grep -b 'search-text' /dev/partition > file.txt
OR
grep -a -B[size before] -A[size after] 'text' /dev/[your_partition] > file.txt
Where,

    -i : Ignore case distinctions in both the PATTERN and the input files i.e. match both uppercase and lowercase character.
    -a : Process a binary file as if it were text
    -B Print number lines/size of leading context before matching lines.
    -A: Print number lines/size of trailing context after matching lines.

To recover text file starting with "nixCraft" word on /dev/sda1 you can try following command:
# grep -i -a -B10 -A100 'nixCraft' /dev/sda1 > file.txt

Next use vi to see file.txt. This method is ONLY useful if deleted file is text file. If you are using ext2 file system, try out recover command. .

Thursday, 20 September 2012

Important UNIX Commands!!

Important UNIX Commands!! 
Please find below important UNIX commands   which we generally use in our day to day activities.