Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> kwatch.sh Review (WIP)

kwatch.sh Review (WIP)

From: Ethan Post <nospam_at_nowhere.com>
Date: Sat, 24 Aug 2002 06:26:16 GMT
Message-ID: <cGF99.233944$sA3.378760@rwcrnsc52.ops.asp.att.net>


Long while back I made some modifications to Connor McDonald's alert log script available on his site. I thought it was neat the way it used the dd command to copy the new chunk of the log and then only check that chunk for errors. The script below is something similar to this except it checks the modified time and size first to see if file has any new changes. If so it grabs the chunk of the file it will need to scan (either the new portion or the whole file). This method does not require a complete copy of the file each time which is what Connor's does. I haven't added anything other than the part that gets the new information from the file. Free free to make any recommends. I am ksh hack at times and miss more obvious ways of doing things. It is self documenting of course :)

#!/usr/bin/ksh

# =================================================================
# NAME
# kwatch.sh
#
# SYNOPSIS
#
# DESCRIPTION
#
# USER COMMANDS
#
# NOTES
#
# =================================================================

TEMP=/tmp
WORK_FILE=$TEMP/kwatch.tmp
TEMP_FILE=$TEMP/$$.tmp
FILE=$1 touch $WORK_FILE

# Make sure $FILE exists.

if [[ -f "$FILE" ]]; then

   OLD_LS=$( egrep "$FILE" $WORK_FILE )
   CUR_LS=$( ls -l $FILE )
   CUR_MOD_TIME=$( echo $CUR_LS | awk '{printf("%s %s %s \n",$6,$7,$8)}' )
   OLD_MOD_TIME=$( echo $OLD_LS | awk '{printf("%s %s %s \n",$6,$7,$8)}' )
   CUR_SIZE=$( echo $CUR_LS | awk '{ print $5 }' )
   OLD_SIZE=$( echo $OLD_LS | awk '{ print $5 }' )

   if [[ ! -z "$OLD_LS" ]]; then
      if [[ "$OLD_MOD_TIME" != "$CUR_MOD_TIME" || "$CUR_SIZE" !=
"$OLD_SIZE" ]]; then
         if (( $CUR_SIZE > $OLD_SIZE )); then
            dd if=$FILE of=$TEMP_FILE bs=$OLD_SIZE skip=1
            CHECK_FILE=$TEMP_FILE
         else
            CHECK_FILE=$FILE
         fi

         LINE_NO=$( fgrep -n "$FILE" $WORK_FILE | awk -F: '{ print $1 }' )
         cat $WORK_FILE | sed ${LINE_NO}d > $TEMP_FILE
         ls -l $FILE >> $TEMP_FILE
         mv $TEMP_FILE $WORK_FILE

      fi
   else
       ls -l $FILE >> $WORK_FILE
       CHECK_FILE=$FILE

   fi

else

   # $FILE does not exist.
   echo $FILE does not exist.

fi

rm $TEMP_FILE 2> /dev/null Received on Sat Aug 24 2002 - 01:26:16 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US