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.
Category: Java,Linux
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
Category: Linux
Writing by shivdev on Wednesday, 20 of April , 2011 at 9:30 pm
As a developer I’m constantly restarting processes. For instance, if I have 2 Java Process (Server/Web) and an Eclipse Java Process which makes 3 Java Processes. The problem is to kill only the server and web processes and leave the eclipse java process intact.
Solution 1 (The Hard and Manual approach):
Find the java processes and kill them manually
ps -ef | grep java
kill -9 1
kill -9 2
Solution 2 (The Simplified Approach – killjava):
Create an alias or run the following:
ps -A|grep java|sed -e “s/\s*\([0-9]*\).*/\1/”|xargs kill -9
This will kill all java processes – which means you will need to restart eclipse each time you run this.
Solution 3 (The Tuned Approach – killweb):
Create an alias or run the following based on a keyword (say, Web process remote_debug port 4096):
ps -A|grep java|sed -e “s/\s*\([0-9]*\).*/\1/” | xargs ps -p | grep 4096 | sed -e “s/\s*\([0-9]*\).*/\1/” | xargs kill -9
Create an alias or run the following based on a keyword (say, Server process remote_debug port 2048):
ps -A|grep java|sed -e “s/\s*\([0-9]*\).*/\1/” | xargs ps -p | grep 2048 | sed -e “s/\s*\([0-9]*\).*/\1/” | xargs kill -9
This will kill only the specific processes you want to terminate.
Solution 4 (The BEST Way – Combine 1 and 2 in a single alias – killdebug):
Create an alias or run the following (Use egrep to look for multiple keywords above):
ps -A|grep java|sed -e “s/\s*\([0-9]*\).*/\1/” | xargs ps -p | egrep “2048|4096” | sed -e “s/\s*\([0-9]*\).*/\1/” | xargs kill -9
This will kill all processes you WISH to terminate.
I have aliases for Solutions 2, 3 and 4 depending on what I’m trying to do. So there you go – hope that helps!
Category: Linux,Tips and Tricks
Writing by shivdev on Tuesday, 30 of November , 2010 at 4:51 pm
I’ve been trying to do this for a while and finally found out how it’s done.
Use the Shadow option.
In the NX Client Configuration GUI –> General Tab –> Desktop Section –> Select Shadow in the drop down.
Then login and select which session to attach to (Local Machine, or any other session)
That should do it!
Couple of things to remember, even though NX does an excellent job and I love NX:
- Since my local machine has a Dual monitor configuration (with different resolutions), I had some blur issues (even when my client spanned two monitors) – Yes I have 4 monitors (2 for Windows and 2 for Linux)
- When connecting from my laptop (single monitor), the dual monitor layout on the local machine was squeezed into a single screen and made it difficult to read
Category: Linux
Writing by shivdev on Wednesday, 29 of September , 2010 at 4:41 pm
One of the pain points with UNIX is that there are several flavors of Linux and several flavors of Shells. Things that work one way on Solaris (CSH) may not work with CentOS (BASH) or Ubuntu (tcsh). After major struggle and after several trials-and-errors, I figured how a simple thing like exporting display can be so painful if you don’t know how it works.
On the CentOS box where you want to see the DISPLAY (pretty standard)
xhost +
Then simply ssh -X to the remote host and you should be all set: (This is the trick)
ssh -X user@remotehost
xclock &
That’s it folks! Remember to use the -X option with SSH.
Don’t mess with export DISPLAY=SOURCEIP:0.0. This will cause you MAJOR GRIEF.
Category: Linux
Writing by shivdev on Thursday, 22 of July , 2010 at 6:27 pm
Can’t get rid of RPMs and you’re running into errors when there are no dependencies?
For example,
error: “mysql-4.1.22-2.el4” specifies multiple packages
Thanks to Hacktux, found the reason is that the RPMs got installed for mysql.i386 and mysql.x86_64
rpm -q –queryformat “%{name}.%{arch}\n” mysql
mysql.i386
mysql.x86_64
To solve the problem just execute
rpm -qa | grep mysql | xargs rpm -e –nodeps –allmatches
You should be good to go.
Category: Linux