Saturday, September 4, 2010

Sanity check on WebLogic classpath

A constant nightmare for WebLogic administrators is to make sure your WebLogic classpath doesn't contain crap.

This (where 3757 is the PID) prints the classpath:

jrcmd 3757 print_properties | grep java.class.path

java.class.path=entry1:entry2:....



Here is a script to check the integrity of the classpath:



pid=$1
entries=`jrcmd ${pid} print_properties | grep java.class.path | awk -F'=' '{print $2}' | tr ':' '\n'`
entriesList=(${entries})
for i in `seq 0 $((${#entriesList[@]}-1))`;
do
  entry=${entriesList[$i]}
  if [ -f ${entry} ]
    then echo "FILE ${entry} exists"
    else
      if [ -d ${entry} ]
      then echo "DIRECTORY ${entry} exists"
      else
         echo "NONEXISTING ${entry}"
      fi
  fi
done



or if running Sun, use
jinfo -sysprops ${pid} | grep java.class.path | awk -F'=' '{print $2}'


If you have problems executing jrcmd $pid print_properties - for instance some security restrictions, you can try this:

allcps=`ps -ef | grep weblogic | tr ' ' '\n' | grep java.class.path | awk -F'=' '{print $2}'` 
#here we have many lines, each with a classpath
allcpsList=(${allcps})
for j in `seq 0 $((${#allcpsList[@]}-1))`; 
do    
 line=(${allcpsList[$j]})
 entriesList=`echo $line | tr ':' '\n'`
 entriesListSplit=(${entriesList})
 for i in `seq 0 $((${#entriesListSplit[@]}-1))`;
 do
          entry=${entriesListSplit[$i]}
   if [ -f ${entry} ]
     then echo "FILE ${entry} exists"
     else
       if [ -d ${entry} ]
       then echo "DIRECTORY ${entry} exists"
       else
   echo "NONEXISTING ${entry}"
       fi
   fi
        done
done





running the script followed by | sort | more gives interesting results

No comments: