Check Size of a File in BASH Script – alert.log oracle help

Size of a File in a directory location can be checked using a small shell script.

#!/bin/bash
str_LogName = "/u01/SAQIB/MyFile"
int_fileSIZE=$(du -b $str_LogName | awk '{ print $1 }')
echo $str_LogName

However, if we want to see if the size is greater than a particular amount say 3MB, we will use the following script.

#!/bin/bash
str_LogName = "/u01/SAQIB/MyFile"
#Size to be checked in Bytes
int_checkSIZE=3145728
int_fileSIZE=$(du -b $str_LogName | awk '{ print $1 }')
if [[ $int_fileSIZE -le  $int_checkSIZE ]];
then
        echo "Size is Lesser then 3 MB"
        # Size in Human Readable Format.
        echo du -bh $str_LogName

else
        echo "Size is More than 3MB:"
fi

 Now if we want to check the size of alert.log file in the database and see if its more than 3MB, copy it with a new name and recreate alert.log file.

#!/bin/bash
##########################################################################
#
# AUTHOR: Saqib Mujtaba
# SCRIPT: Check the size of Size of ALert.Log File and if its more than 3MB it creates a Backup and Nullifies the Older Original One.
# DATED : 18/02/2014
# 
#
##########################################################################
#Getting the SID name
str_SIDINSTANCE=$( cat /etc/oratab|grep -v "^#"|cut -d: -f1 -s|head -1)

#File Location of Alert.Log File <EDIT AS PER YOURS>
str_FileLocation="/u01/oracleSID/db/tech_st/11.1.0/admin/oracleSID_pm-ora-qwe-qa-wsx/diag/rdbms/oracleSID/oracleSID/trace/"
str_FileName="alert_oracleSID.log"
str_LogName=$str_FileLocation$str_FileName
#echo $str_LogName
#File Location of New Backup
str_NewLogName="alert_LOG_bkp_$str_SIDINSTANCE-$(date +"%m-%d-%Y-%H:%M").log"
str_NewLogLocation=$str_FileLocation$str_NewLogName
#echo $str_NewLogLocation
#Check alert.log File Size
int_fileSIZE=$(du -b $str_LogName | awk '{ print $1 }')
#CHECK TO SIZE IN BYTES
int_checkSIZE=3145728
#echo $int_fileSIZE " & " $int_checkSIZE
#Check Size is greater than 3 MB
if [[ $int_fileSIZE -le  $int_checkSIZE ]];
then
        echo "NO Need to Backup - Size is Lesser then 3 MB"
        echo du -bh $str_LogName

else
        #echo "Size is More:"
	cp -f $str_LogName $str_NewLogLocation
        if [[ $? -eq 0 ]];
        then
                rm -f $str_LogName
                touch $str_LogName
                echo "Alert Log Backup File [ $str_NewLogName ] Created Successfully - Thanks!!"
        else
                echo "Failed to Create Alert Log Backup"
        fi
fi
Oracle’s alert.log chronologically records messages and errors arising from the daily database operation. Also, there are pointers to trace files and dump files.

These messages include

  • startups and shutdowns of the instance

  • Messages to the operator console
  • Errors causing trace files.
  • Create, alter and drop SQL statements on databases, tablespaces and rollback segments.
  • Errors when a materialized view is refreshed.
  • ORA-00600 (internal) errors.
  • ORA-01578 errors (block corruption)
  • ORA-00060 errors (deadlocks)
alert.log is a text file that can be opened with any text editor. The directory where it is found can be determined by the background_dump_dest initialization parameter:
select value from v$parameter where name = 'background_dump_dest';

If the background_dump_dest parameter is not specified, Oracle will write the alert.log into the $ORACLE_HOME/RDBMS/trace directory.

 
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: