Thursday, July 15, 2010

Very bizarre problem when running JDK 32 bit on a 64 bit Linux box

I just noticed a very weird problem if you use a 32bit Sun JDK on a 64bit RedHat Linux.

The "user.home" system properties, returned by System.getProperty("user.home"), has the value of "?". Same thing happens with "" property.

I'm not sure why this is but seems like a bug too me.

-bash-3.00$ /shares/jdk/hotspot1.6.0_16/bin/java ShowSystemProps | grep "user" = US
user.dir = /home/hhuynh
user.home = ?
user.timezone = = ?
user.language = en

Correct values if I used 64bit JDK

-bash-3.00$ /shares/jdk/hotspot1.6.0_16_x64/bin/java ShowSystemProps | grep "user" = US
user.dir = /home/hhuynh
user.home = /export2/homes/hhuynh
user.timezone = = hhuynh
user.language = en

This bug leads to Maven creating the local repository under the current working dir: "./?/.m2/repository" and leads to many confusing problems down the road.

Wednesday, July 14, 2010

Simple Bash script to rotate log

If you have some program that doesn't handle its own log rotation, you could use the below script to rotate the log. Ideally, you would call this script in a daily crob job.

if [ ! -f $logfile ]; then
echo "log file not found $logfile"
exit 1
timestamp=`date +%Y%m%d`
cp $logfile $newlogfile
cat /dev/null > $logfile
gzip -f -9 $newlogfile