Replace end of lines with commas in sed

Need to extract numbers and create a comma separated list:

$ sed -e :label -e N -e ‘s/\n/, /’ -e ‘s/[ |]//g’ -e tlabel <<xxxx
> |     919 |
> |    1027 |
> |    1593 |
> |    1595 |
> xxxx
919,1027,1593,1595

 

 

Posted in unix | Tagged , , , | Leave a comment

Useful java parameters

“Good” set of java parameters to run “generic” application like tomcat:

JAVA_OPTS=”-d64 -Xms512m -Xmx512m -XX:MaxPermSize=128m”
JAVA_OPTS=”-Djava.awt.headless=true -Djava.net.preferIPv4Stack=true $JAVA_OPTS”
JAVA_OPTS=”-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:-TraceClassUnloading $JAVA_OPTS”
JAVA_OPTS=”-XX:+HeapDumpOnOutOfMemoryError -XX:+HeapDumpOnCtrlBreak -XX:HeapDumpPath=/home/tomcat/snapshots $JAVA_OPTS”

These are not good but they are working options to enable jmxremote console.

JAVA_OPTS=”-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1888 -Djava.rmi.server.hostname=test.com  $JAVA_OPTS”
To exit on OutOfMemoryError in jdk1.6:

Unix:
-XX:OnOutOfMemoryError="kill -9 %p"

Windows:
-XX:OnOutOfMemoryError="taskkill /F /PID %p"

JRockIT:
-XXexitOnOutOfMemory

Posted in java | Tagged , , , , | Leave a comment

Weblogic starts slow

I had a lot of troubles starting Oracle Weblogic 10.3g under linux (CentOS 5.2). It took anywhere between 5 to 20 minutes from the time I ran startup script to the point when Weblogic actually started. Here is typical log:

<Mar 12, 2009 12:35:34 PM EDT> <Info> <Management> <BEA-141107> <Version: WebLogic Server 10.3  Fri Jul 25 16:30:05 EDT 2008 1137967 >
<Mar 12, 2009 12:46:37 PM EDT> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING>

Turns out Weblogic uses random number generator during start up. Because of the bug in java it reads ‘randomness’ from /dev/random. /dev/random is very good random numbers generators but it is extremely slow. It takes sometimes 10 minutes or more to generate one number. /dev/urandom is not that good, but it is instant.
Java somehow maps /dev/urandom file to /dev/random. That’s why default settings in $JAVA_HOME/jre/lib/security/java.security are useless.

Possible solutions:
1) Add  “-Djava.security.egd=file:/dev/./urandom” (/dev/urandom does not work) to java parameters.

Worse but working solution is:
2) mv /dev/random /dev/random.ORIG ; ln /dev/urandom /dev/random

3) Best solution is to change $JAVA_HOME/jre/lib/security/java.security
Replace securerandom.source with

securerandom.source=file:/dev/./urandom

This problem does not happen under windows because it uses different implementation of /dev/random.

It takes seconds to start weblogic server now.

Posted in Uncategorized | Tagged , , , | 38 Comments

strace – trace system calls and signals

Nice little program that might be used in linux to find what files were open by the process. For example:

strace ls 2>&1|grep “open”

Posted in unix | Tagged , , , | Leave a comment

How to find what application is using network port in linux?

netstat -nlp will give you an idea.

[root@os]# netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:9921                0.0.0.0:*                   LISTEN      10982/ora_d000_orcl
tcp        0      0 10.10.10.10:1521           0.0.0.0:*                   LISTEN      12516/tnslsnr
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      6561/sshd
udp        0      0 127.0.0.1:1052              0.0.0.0:*                               10920/ora_pmon_orcl
Posted in unix | Tagged , , , , | Leave a comment

When you use ‘find’ and ‘zip’ in one sentence…

Instead of

find albums -name *.jpg -not -name *.sized.jpg -not -name *.thumb.jpg -not -name *.highlight.jpg -exec zip -r -1 album.zip {} ;&

use

find albums -name *.jpg -not -name *.sized.jpg -not -name *.thumb.jpg -not -name *.highlight.jpg -print| zip -1 album.zip -@

It will take 5 minutes instead of 5 hours on 500MB archive.

Posted in unix | Tagged , | Leave a comment

Permanent Redirects in Apache

These are simple and often overlooked rewrite rules to generate Permanent Redirects for sister domains.

UseCanonicalName On

ServerName www.olegshpak.com
ServerAlias olegshpak.com
ServerAlias www.niteart.com
ServerAlias niteart.com

RewriteEngine on
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)$
RewriteRule .* – [F]
RewriteCond %{HTTP_HOST} ^niteart.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.niteart.com$ [OR]
RewriteCond %{HTTP_HOST} ^olegshpak.com$
RewriteRule ^(.*)$    http://%{SERVER_NAME}$1 [R=permanent,L]

If your configuration requires you to set UseCanonicalName to Off then use a real server name instead of variable in RewriteRule.

Why is it important? Main reason is SEO. With permanent redirect search engines are not going to think that you have two or more different websites with the same content.

Posted in Apache Tips | Tagged , , , | Leave a comment