Thursday, January 3, 2013

Application Server(Oracle Weblogic) Cache Clearance Script

Purpose:

This Shell script tutorial describes and shows how to clear multiple managed application server caches at one shot.

Scenario:

You are an application server administrator at industryvertical.co.in Corporate.You maintaining so many environments under your control.After every deployment and before starting managed servers you need to remove managed server cache(which holds some EJB related stuff) and temp locations manually.You are bored up because of this repetitive activity.So you begun to write a shell script for this purpose.

Script Code:
#
#Script to perform the temp and cache clearance!!
#
clear

set_environment_variables()
{
DOMAIN_HOME=/opt/kshop/Oracle/Middleware/user_projects/domains/
DOMAIN_NAME=base_domain
SERVER_DIR=${DOMAIN_HOME}/${DOMAIN_NAME}/servers
}

create_servers_list()
{
        ls  ${SERVER_DIR}|grep -v Admin|grep -v domain|grep -v logtail > list_of_servers.txt
}

clear_server_cache()
{
        NO_OF_SERVERS=$(cat /home/kshop/Base_Domain/list_of_servers.txt|wc -l)
        i=1
        while [ $i -le $NO_OF_SERVERS ]
        do
        SERVER_NAME=$(cat /home/kshop/Base_Domain/list_of_servers.txt|tr '\n' ':'|cut -d":" -f$i)
        cd ${SERVER_DIR}
         echo "Cache and Temp Clearance is in Progress for ${SERVER_NAME}"
         rm -r ${SERVER_NAME}/cache/diagnostics
         rm -r ${SERVER_NAME}/cache/EJBCompilerCache
         rm -r ${SERVER_NAME}/tmp/${SERVER_NAME}.lok
         rm -r ${SERVER_NAME}/tmp/WebServiceUtils.ser
         rm -r ${SERVER_NAME}/tmp/_WL_internal
         rm -r ${SERVER_NAME}/tmp/_WL_user
         i=`expr $i + 1`
        done
        exit 1
}

#Main Fucntion starts here
set_environment_variables
create_servers_list
clear_server_cache 

I hope that this would help some app server administrator who doing this kind of task repetitively.

No comments:

Post a Comment