Generating Thread Dumps in Java on Linux

Writing by shivdev on Friday, 6 of May , 2011 at 9:43 pm

Got deadlock?

killall -QUIT java

This will log the thread dumps for your java processes wherever the processes standard output is configured.

Leave a comment

Category: Java,Linux

Delete Lines in a Log File using Shell Scripts

Writing by shivdev on Friday, 6 of May , 2011 at 7:35 am

If you want to delete a PATTERN from a Log File.

$ sed ‘/PATTERN/d’ server.log > newServer.log

If you want to write a small script to do it:

#!/bin/sh
files="/home/user/app/logs/*.log"
for f in $files
do
  sed '/PATTERN/d' $f > $f.out
  mv  $f.out $f
done

Now if you want to do it for a bunch of log files, I wrote a script that works for me:

#!/bin/sh

# Check usage
if [ $# -lt 2 ] ; then
    echo "Syntax: $0  <DeleteString> <Directory/Pattern>"
    echo "Example: $0 DefaultRequestDestination ./logs/*webser*.log*"
    exit 1
fi

PATTERN=$1
shift

# Print Warning Info: About to mess with your logs
for f in $@
do
	echo "Will Delete Lines Containing: $PATTERN in file: $f"
done

read -p "Are you sure? " -n 1
if [[ $REPLY =~ ^[Yy]$ ]]; then

	echo "OK Cleaning... "

	# Loop over files pattern
	files=$@
	for f in $files
	do
		echo "Cleaning: $f"
		sed "/"${PATTERN}"/d" $f > $f.out
		mv  $f.out $f
	done
fi

Leave a comment

Category: Linux

Shivdev Kalambi's Blog

Shivdev Kalambi is a Principal Software Engineer working at ArcSight. He has over 11 years' experience in software development and has worked with several technologies and played different roles and contributed to all phases of projects. Other non-tech activies include Ping-pong, Racquetball, Rock Climbing at PG and Swimming.