#!

/bin/sh ################################################################# # Author : Arjan Goos # # Date : 03-06-2008 # # # # Purpose : Clean log files Oracle Application Server # # # # History : # # --------------------------------------------------------------# # Date |Author |Description # # --------------------------------------------------------------# # 03-06-2008 |Arjan Goos |Creation # # # ################################################################# SCRIPT=`basename $0` SCRIPT_PATH="/$ORACLE_HOME/scripts/clean_log" HOST_NAME=`hostname` DATE=`date "+%d-%m-%y"` STATUS_FILE=$SCRIPT_PATH/log/status-${SCRIPT}_${HOST_NAME}_${DATE}.txt MAILADRES="sangeeth.talluri@tatatel.co.in" DU_TOTAL=0 mail_logfile() { mail -s "Clean log files $HOST_NAME - Oracle home: $ORACLE_HOME ( $DATE )" $MAILADRES < $STATUS_FILE } disk_usages_dir() { DUH=`du -hc | grep -i total | awk -F"total" '{ print $1 }'` DIR=`pwd` } disk_usages_home() { DU_HOME=`du -c | grep -i total | awk -F"total" '{ print $1 }'` DU_HOME=`expr $DU_HOME / 1024` } clean_apache() { echo " Start Clean Up Apache logging" >> $STATUS_FILE echo "" >> $STATUS_FILE cd $ORACLE_HOME/Apache/Apache/logs disk_usages_dir echo " Disk Usages in $DIR before $SCRIPT: $DUH." >> $STATUS_FILE FILE="*_log.*" echo " These log files are removed:" >> $STATUS_FILE for LOG_FILE in `find ./ -name "$FILE" -mtime +"$TIME" -print 2>&1` do echo " $LOG_FILE" >> $STATUS_FILE rm $LOG_FILE done

log*" rotate_files # Delete old rotated log files delete_files disk_usages_dir echo " Disk Usages in $DIR after $SCRIPT: $DUH." >> $STATUS_FILE echo "" >> $STATUS_FILE echo " Ready Clean Up Application Server Control" >> $STATUS_FILE echo "" >> $STATUS_FILE } clean_oc4j_instances() { echo " Start Clean Up OC4J Instances" >> $STATUS_FILE echo "" >> $STATUS_FILE cd $ORACLE_HOME/j2ee >> $STATUS_FILE # Get all oc4j_instances from the opmn." >> $STATUS_FILE # Rotate log files FILE="*.log" rotate_files # Delete old rotated log files delete_files disk_usages_dir echo " Disk Usages in $DIR after $SCRIPT: $DUH.disk_usages_dir echo " Disk Usages in $DIR after $SCRIPT: $DUH." >> $STATUS_FILE # Rotate log files FILE="*." >> $STATUS_FILE echo "" >> $STATUS_FILE echo " Ready Clean Up Apache logging" >> $STATUS_FILE echo "" >> $STATUS_FILE } clean_application_server_control() { echo " Start Clean Up Application Server Control" >> $STATUS_FILE echo "" >> $STATUS_FILE cd $ORACLE_HOME/opmn/logs >> $STATUS_FILE disk_usages_dir echo " Disk Usages in $DIR before $SCRIPT: $DUH.> /dev/null echo " Ready OC4J_CONTAINER: $OC4J_INSTANCE." >> $STATUS_FILE cd $OC4J_INSTANCE/log disk_usages_dir echo " Disk Usages in $DIR before $SCRIPT: $DUH.xml for OC4J_INSTANCE in `grep -i module-id=\"OC4J\" $ORACLE_HOME/opmn/conf/opmn." >> $STATUS_FILE cd .xml | awk -F'<process-type id=' '{ print $2 }' | awk -F" " '{ print $1 }' | sed 's/\"//g'` do echo " Start OC4J_CONTAINER: $OC4J_INSTANCE." >> $STATUS_FILE echo "" >> $STATUS_FILE done echo "" >> $STATUS_FILE echo " Ready Clean Up OC4J Instances" >> $STATUS_FILE echo "" >> $STATUS_FILE } clean_webcache() .

$DATE" echo " $LOG_FILE to $LOG_FILE.*" echo " These archive files are removed:" >> $STATUS_FILE for LOG_FILE in `find .archive.archive. then echo " Start Clean Up WebCache" >> $STATUS_FILE echo "" >> $STATUS_FILE cd $ORACLE_HOME/webcache/log >> $STATUS_FILE disk_usages_dir echo " Disk Usages in $DIR before $SCRIPT: $DUH.archive./ -name "$FILE" -mtime +"$TIME" -print 2>&1` do echo " $LOG_FILE" >> $STATUS_FILE rm $LOG_FILE done echo "" >> $STATUS_FILE } find_large_log_files() { cd $ORACLE_HOME echo "" >> $STATUS_FILE echo " Overview big remaining log files (manual action required):" >> $STATUS_FILE ." >> $STATUS_FILE # Rotate log files FILE="*_log" rotate_files # Delete old rotated log files delete_files disk_usages_dir echo " Disk Usages in $DIR after $SCRIPT: $DUH./ -name "$FILE" -size +"$ROTATE_SIZE" -print | grep -v "archive" 2>&1` do #echo "cp $LOG_FILE $LOG_FILE.{ if [ -d $ORACLE_HOME/webcache/log ]." >> $STATUS_FILE echo "" >> $STATUS_FILE echo " Ready Clean Up WebCache" >> $STATUS_FILE echo "" >> $STATUS_FILE fi } rotate_files() { #This function rotates the log files when the file is bigger than $ROTATE_SIZE echo " These files are rotated: " >> $STATUS_FILE for LOG_FILE in `find .$DATE" >> $STATUS_FILE cp $LOG_FILE $LOG_FILE.archive.$DATE cp /dev/null $LOG_FILE done echo "" >> $STATUS_FILE } delete_files() { #This function removes the rotated log files when the file is older than $TIME FILE="*.

" >> $STATUS_FILE ." >> $STATUS_FILE DU_HOME_START=$DU_HOME disk_usages_home DU_HOME_STOP=$DU_HOME echo " Total Disk Usage $ORACLE_HOME after $SCRIPT : $DU_HOME MB." >> $STATUS_FILE cd $ORACLE_HOME disk_usages_home echo "" >> $STATUS_FILE ### MAIN PROG ### Apache log clean_apache ### Application Server Control logs clean_application_server_control ### OC4J instances clean_oc4j_instances ### Webcache clean_webcache #TO_DO #application specific logging find_large_log_files echo "" >> $STATUS_FILE echo " Total Disk Usage $ORACLE_HOME before $SCRIPT : $DU_HOME MB./ -name "*log*" -size +"2048k" -mtime +"$TIME" -exec ls -lh {} \. then echo "Start op: $0 <files older than DATE>" exit 1 fi #ORACLE_HOME=$1 TIME=$1 #Files bigger than 2 Mb are rotated ROTATE_SIZE="2048k" #ROTATE_SIZE="10k" clear echo "Start of the $SCRIPT on `date`: $HOST_NAME." >> $STATUS_FILE find . | awk '{ print " " $9 " size: " $5 }' >> $STATUS_FILE echo "" >> $STATUS_FILE } cd $SCRIPT_PATH #MAIN if [ $# != 1 ].echo "" echo " These *.$DU_HOME_STOP` MB." >> $STATUS_FILE echo "" >> $STATUS_FILE echo " Total Cleared Disk Space $ORACLE_HOME by $SCRIPT: `expr $DU_HOME_START ." >> $STATUS_FILE echo "" >> $STATUS_FILE for ORACLE_HOME in `cat /etc/oratab | grep -v "^#" | grep -v "^agent" | awk -F":" '{ print $2 }'` do if [ -n ${ORACLE_HOME} ].log files are in the $ORACLE_HOME with a size larger than $ROTATE_SIZE and older than $TIME day(s). then echo " Start Oracle Home: $ORACLE_HOME.

echo echo echo echo fi done "" >> $STATUS_FILE " Ready Oracle Home: $ORACLE_HOME." >> $STATUS_FILE "" >> $STATUS_FILE "" >> $STATUS_FILE echo "" >> $STATUS_FILE echo "Ready of the $SCRIPT on `date`" >> $STATUS_FILE echo "" >> $STATUS_FILE echo "" >> $STATUS_FILE mail_logfile exit 0 .

Sign up to vote on this title
UsefulNot useful