[HPADM] No log entries for scripts.

From: brian irvin (brian944us@yahoo.com)
Date: Thu Jan 12 2006 - 11:44:23 EST


Team:

Happy New Year!!!!

I am attaching two scripts. These Scripts are supposed
to trim cron log file (/var/adm/cron/log) and oracle
listener log
(/opt/oracle/817/network/log/list817.log), both log
files are getting trimmed properly ,but I found that,
there is no log entries for both cron log and listner
log files after deploying these 2 scripts. Oracle cron
jobs are working properly. I am missing something in
the scripts. Please Help.

Thanks

Brian.

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

#!/usr/bin/ksh
###################################################################
###################################################################
# SCRIPT NAME : OraclelogFileTrim.sh
# AUTHOR : Brian Irvin
# DATE : January 06, 2006
# VERSION NO : 1.0
# PURPOSE : This Script runs as a cron every month on the first day.
# trims the oracle log file to avoid file system alarm
# Keep last two months backup files and deletes the log files which
# are 2 months old
#
#
################## MODIFICATION HISTORY #######################
#
# AUTHOR DATE CHANGED CHANGE HISTORY
# VERSION
#-----------------------------------------------------------------------------
#
# Brian Irvin 01/06/2006 1.0 Created
#
###################################################################

APP_FILE=/opt/net/ORACLE_LOG_FILETRIM/data/OraclelogFileTrim.dat
LOG_FILE_DIR=/opt/oracle/817/network/log
MOVE_FILE_DIR=/opt/oracle/817/network/log
LOG_FILE=/opt/net/ORACLE_LOG_FILETRIM/log/OraclelogFileTrim.log
TEMP_FILE=/opt/net/ORACLE_LOG_FILETRIM/log/temp.log

touch $LOG_FILE
chmod 744 $LOG_FILE

# Output and Errors will be sent to CmclusterFileTrim.log
exec >> $LOG_FILE 2>> $LOG_FILE

Prev_month()
{
   month=`date +'%m'`
   year=`date +'%Y'`
   prevmonth=`expr $month - 1`

   if [ $prevmonth -lt 1 ]
   then
        prevmonth=12
        year=`expr $year - 1`
   fi
   if [ $prevmonth -le 9 ]
   then
        prevmonth="0$prevmonth"
   fi
}

Move_files()
{
   cdate=`date +'%d'`
   cmonth=`date +'%m'`
   while read line
   do
        if [ cdate -eq 1 ]
        then
                MOVE_LOG=$MOVE_FILE_DIR"/$line.$year$prevmonth"
        else
                if [ cmonth -eq 1 ]
                then
                year=`expr $year + 1`
                fi
                MOVE_LOG=$MOVE_FILE_DIR"/$line.$year$cmonth"
                
        fi

        if [ -f $LOG_FILE_DIR"/$line" ]
        then
                total=`cat $LOG_FILE_DIR/$line|wc -l`
                let "total = $total - 100"

                if [ -f $MOVE_LOG ]
                then
                echo "file being moved ---> $LOG_FILE_DIR/$line "
                head -$total $LOG_FILE_DIR"/$line" >> $MOVE_LOG 2>/dev/null
                tail -1000 $LOG_FILE_DIR"/$line" >> $TEMP_FILE 2>/dev/null
                mv $TEMP_FILE $LOG_FILE_DIR"/$line" 2>/dev/null
                else
                head -$total $LOG_FILE_DIR"/$line" >> $MOVE_LOG 2>/dev/null
                tail -1000 $LOG_FILE_DIR"/$line" >> $TEMP_FILE 2>/dev/null
                mv $TEMP_FILE $LOG_FILE_DIR"/$line" 2>/dev/null
                fi
                
         fi
   done<$APP_FILE
}

delete_logfiles()
{
   month=`date +'%m'`
   year=`date +'%Y'`
   deletionPeriod=2

   if [ $month -le $deletionPeriod ]
   then
        monthDelete=`expr 12 + $month - $deletionPeriod`
        year=`expr $year - 1`
   else
        monthDelete=`expr $month - $deletionPeriod`
   fi

   if [ $monthDelete -le 9 ]
   then
        monthDelete="0$monthDelete"
   fi

   while read line
   do
        if [ -f $MOVE_FILE_DIR"/$line.$year$monthDelete" ]
        then
                rm -f $MOVE_FILE_DIR"/$line.$year$monthDelete" 2>/dev/null
                echo "`date '+%D %T'` $MOVE_FILE_DIR/$line.$year$monthDelete removed"
        fi
  done<$APP_FILE
}

##############MAIN PGM #######################
   Prev_month
   echo "`date '+%D %T'` Moving files for $year/$prevmonth"
   Move_files
   delete_logfiles
   while read line
   do
        touch $LOG_FILE_DIR"/$line"
        chmod 644 $LOG_FILE_DIR"/$line"
        chown oracle:dba $LOG_FILE_DIR/list*
   done<$APP_FILE
#############################################


#!/usr/bin/ksh
# SCRIPT NAME : CronlogFileTrim.sh
# AUTHOR : Brian Irvin
# DATE : January 06, 2006
# VERSION NO : 1.0
# PURPOSE : This Script runs as a cron every month on the first day.
# trims the cron log file to avoid file system alarm
# Keep last two months backup files and deletes the log files which
# are 2 months old
#
#
################## MODIFICATION HISTORY #######################
#
# AUTHOR DATE CHANGED CHANGE HISTORY
# VERSION
#-----------------------------------------------------------------------------
#
# Brian Irvin 01/06/2006 1.0 Created
#
#
###################################################################

APP_FILE=/opt/net/CRON_LOG_FILETRIM/data/CronlogFileTrim.dat
LOG_FILE_DIR=/var/adm/cron
MOVE_FILE_DIR=/var/adm/cron
LOG_FILE=/opt/net/CRON_LOG_FILETRIM/log/CronlogFileTrim.log
TEMP_FILE=/opt/net/CRON_LOG_FILETRIM/log/temp.log

touch $LOG_FILE
chmod 744 $LOG_FILE

# Output and Errors will be sent to CmclusterFileTrim.log
exec >> $LOG_FILE 2>> $LOG_FILE

Prev_month()
{
   month=`date +'%m'`
   year=`date +'%Y'`
   prevmonth=`expr $month - 1`

   if [ $prevmonth -lt 1 ]
   then
        prevmonth=12
        year=`expr $year - 1`
   fi
   if [ $prevmonth -le 9 ]
   then
        prevmonth="0$prevmonth"
   fi
}

Move_files()
{
   cdate=`date +'%d'`
   cmonth=`date +'%m'`
   while read line
   do
        if [ cdate -eq 1 ]
        then
                MOVE_LOG=$MOVE_FILE_DIR"/$line.$year$prevmonth"
        else
                if [ cmonth -eq 1 ]
                then
                year=`expr $year + 1`
                fi
                MOVE_LOG=$MOVE_FILE_DIR"/$line.$year$cmonth"
                
        fi

        if [ -f $LOG_FILE_DIR"/$line" ]
        then
                total=`cat $LOG_FILE_DIR/$line|wc -l`
                let "total = $total - 100"

                if [ -f $MOVE_LOG ]
                then
                echo "file being moved ---> $LOG_FILE_DIR/$line "
                head -$total $LOG_FILE_DIR"/$line" >> $MOVE_LOG 2>/dev/null
                tail -1000 $LOG_FILE_DIR"/$line" >> $TEMP_FILE 2>/dev/null
                mv $TEMP_FILE $LOG_FILE_DIR"/$line" 2>/dev/null
                else
                head -$total $LOG_FILE_DIR"/$line" >> $MOVE_LOG 2>/dev/null
                tail -1000 $LOG_FILE_DIR"/$line" >> $TEMP_FILE 2>/dev/null
                mv $TEMP_FILE $LOG_FILE_DIR"/$line" 2>/dev/null
                fi
                
         fi
   done<$APP_FILE
}

delete_logfiles()
{
   month=`date +'%m'`
   year=`date +'%Y'`
   deletionPeriod=2

   if [ $month -le $deletionPeriod ]
   then
        monthDelete=`expr 12 + $month - $deletionPeriod`
        year=`expr $year - 1`
   else
        monthDelete=`expr $month - $deletionPeriod`
   fi

   if [ $monthDelete -le 9 ]
   then
        monthDelete="0$monthDelete"
   fi

   while read line
   do
        if [ -f $MOVE_FILE_DIR"/$line.$year$monthDelete" ]
        then
                rm -f $MOVE_FILE_DIR"/$line.$year$monthDelete" 2>/dev/null
                echo "`date '+%D %T'` $MOVE_FILE_DIR/$line.$year$monthDelete removed"
        fi
  done<$APP_FILE
}

##############MAIN PGM #######################
   Prev_month
   echo "`date '+%D %T'` Moving files for $year/$prevmonth"
   Move_files
   delete_logfiles
   while read line
   do
        touch $LOG_FILE_DIR"/$line"
        chmod 644 $LOG_FILE_DIR"/$line"
        chown root:root $LOG_FILE_DIR"/$line"
   done<$APP_FILE
#############################################

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:51 EDT