Sunday, February 8, 2015

Clean up Weblogic Server Cache

In many situations we would need to clean up weblogic server cache and we need to be careful while doing this. It's better to have a script which can do our job can help in reducing manual effort/human errors.

Following script can be run using 2 parameters (domain name & server name). This is required because there may be multiple domains in one machine and server name needs to mentioned as we can clean-up any server depending on the need basis.

clearWLCache.sh 


#!/bin/ksh

usage()
{
 echo "\n!!!!!Usage!!!!!!!"
 echo
 echo " clearWLCache.sh "
 echo "\ne.g. clearWLCache.sh myDomain myServer"
 echo
}

if [ $# -ne 2 ]
then
 usage
 exit 2
fi

domain=$1
server=$2
WLS_HOME=/opt/fmw

state=`cut -f1 -d ":" $WLS_HOME/domains/${domain}/servers/${server}/data/nodemanager/${server}.state`
echo "Server state is $state"

if [ $state = RUNNING -o $state = STARTING ]
then
    echo "Server is in $state mode, please shutdown and then use this script "
    exit
else

 if [ -d $WLS_HOME/domains/${domain}/servers/${server} ]
 then
   path=$WLS_HOME/domains/${domain}/servers/${server}
   rm -Rf $path/cache/*
   rm -Rf $path/tmp/*
   echo "Cache clean-up completed successfully"
   exit
 else
   echo ${domain} "or" ${server} "doesn't exists, please check"
   exit
 fi

fi

echo "There was some error, script not executed, please check the command/server name/admin name"
exit

No comments:

Post a Comment