Shell Scripting

Friday, May 22, 2015

Script to rotate Weblogic .out files

#!/bin/ksh

#This script will rotate all log files
#that are included in DIRLIST below.

#Read in log file directory list from the control file above
DIRLIST=`cat $home/scripts/log_list.ctrl`

for DIRECTORY in $DIRLIST
do

#Rotate archived access and error log files

#If an archived access or errors file doesn't exist,
#then create it.


if [[ ! -a ${DIRECTORY}.05.gz ]];
  then
    touch ${DIRECTORY}.05.gz
#Puts entry into log file.
        echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.05.gz" >> $home/output/wlLogRotate.log
fi

if [[ ! -a ${DIRECTORY}.04.gz ]];
  then
    touch ${DIRECTORY}.04.gz
#Puts entry into log file.
        echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.04.gz" >> $home/output/wlLogRotate.log
fi

if [[ ! -a ${DIRECTORY}.03.gz ]];
  then
    touch ${DIRECTORY}.03.gz
#Puts entry into log file.
        echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.03.gz" >> $home/output/wlLogRotate.log
fi

if [[ ! -a ${DIRECTORY}.02.gz ]];
  then
    touch ${DIRECTORY}.02.gz
#Puts entry into log file.
        echo "- $(date): The following log file didn't exist and is now created: $DIRECTORY.02.gz" >> $home/output/wlLogRotate.log
fi

if [[ ! -a ${DIRECTORY}.01.gz ]];
  then
    touch ${DIRECTORY}.01
        touch ${DIRECTORY}.01.gz
#Puts entry into log file.
        echo "- $(date): The following log files didn't exist and are now created: $DIRECTORY.01 and $DIRECTORY.01.gz" >> $home/output/wlLogRotate.log
fi

#If all of the archived log files are there, then rotate them
if [[ -a ${DIRECTORY}.05.gz ]] && [[ -a ${DIRECTORY}.04.gz ]] && [[ -a ${DIRECTORY}.03.gz ]] && [[ -a ${DIRECTORY}.02.gz ]] && [[ -a ${DIRECTORY}.01.gz ]];

  then

#Log files
    cp -f ${DIRECTORY}.04.gz ${DIRECTORY}.05.gz
    cp -f ${DIRECTORY}.03.gz ${DIRECTORY}.04.gz
    cp -f ${DIRECTORY}.02.gz ${DIRECTORY}.03.gz
    cp -f ${DIRECTORY}.01.gz ${DIRECTORY}.02.gz
#Puts entry into log file.
        echo "- $(date): The following log files have been rotated: $DIRECTORY" >> $home/output/wlLogRotate.log

#Copy current log files
    cp -f ${DIRECTORY} ${DIRECTORY}.01
#Puts entry into log file.
        echo "- $(date): The following log files have been copied to version .01: $DIRECTORY" >> $home/output/wlLogRotate.log

#Remove the .01.gz files
        rm -f ${DIRECTORY}.01.gz
#Puts entry into log file.
        echo "- $(date): The following log .01.gz files have been removed: $DIRECTORY" >> $home/output/wlLogRotate.log

#Zip the log files
    gzip ${DIRECTORY}.01
#Puts entry into log file.
        echo "- $(date): The following .01 log files have been gziped: $DIRECTORY" >> $home/output/wlLogRotate.log

#Null out the working log files so that
#they go down to zero file size
    cat /dev/null > ${DIRECTORY}
#Puts entry into log file.
        echo "- $(date): The following log files have been nulled out: $DIRECTORY" >> $home/output/wlLogRotate.log

fi

done

Script to run node manager in background

Below is the script we can use to run Node manager in background

file1=$home/output/nodemgr10.out
file2=$home/output/nodemgr10.err
suffix=$(date +%s)
newfile1=$home/output/archive/nodemgr10.out.$suffix
newfile2=$home/output/archive/nodemgr10.err.$suffix
cp $file1 $newfile1
cp $file2 $newfile2
nohup $WL_HOME/server/bin/startNodeManager.sh 1>$file1  2>$file2 &

Thursday, May 21, 2015

Patching offline on Weblogic using BSU

1. Take Backup of Middleware home. In case of any problem after patching, we can revert whole Weblogic setup

2. Stop all java Processes  (Admin server/Mange servers and Node mannager if they are running). Also stop all process which are dependant on Weblogic setup.

3. cd $BEA_HOME/utils/bsu/cache_dir

a)rename patch-catalog.xml to some name which will be a backup file
b)Copy the patch with .jar extension to cache_dir(for ex: QR92.jar)
c)cp patch-catalog_15563.xml $BEA_HOME/utils/bsu/cache_dir/patch-catalog.xml

4. cd $BEA_HOME/utils/bsu/

./bsu.sh -view -prod_dir=$BEA_HOME/wlserver_10.3 -status=applied >/home/stelikep/zwblg202/zwblg202_applied_before_srv.txt

./bsu.sh -report  -bea_home=$BEA_HOME > ~/WS103_beforepatch.txt

./bsu.sh -prod_dir=$BEA_HOME/wlserver_10.3 -patchlist=E65J -verbose -install -log=~/zqsextraapda02_srv_E65J.txt

./bsu.sh -view -prod_dir=$BEA_HOME/wlserver_10.3 -status=applied > ~/zqsextraapda02_applied_after_srv.txt

./bsu.sh -report  -bea_home=$BEA_HOME > /home/lg400816/zqsextraapda02/WS103_afterpatch.txt

Once patching completed, we can start Weblogic processes.