Script for executing Oracle Query and send output with mail on Linux Platform

Script for executing Oracle Query and send output with mail function of Linux Platform

Example for executing Oracle Script on Linux Platform and send the output through mail.


# oracle oratab file location
cd /u01/app/oracle/script/
ORATAB=/etc/oratab
if [ ! -f $ORATAB ]
then
exit 1
fi
# Loop for every entry in ORATAB file
cat $ORATAB|grep -v '^$' | while read LINE
do        case $LINE in
\#*)    # Comment-Line in ORATAB
;;        *)
# Setup ORACLE_SID and ORACLE_HOME
# if third field in ORATAB is 'Y'
ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
if [ "$ORACLE_SID" = '*' ]
then
ORACLE_SID=""
fi
ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
#echo ORACLE_SID=$ORACLE_SID
#echo ORACLE_HOME=$ORACLE_HOME
export ORACLE_SID=$ORACLE_SID
export ORACLE_HOME=$ORACLE_HOME
#export PATH=$PATH:$ORACLE_HOME/bin
#export LD_LIBRARY_PATH=$ORACLE_HOME/lib
exit|$ORACLE_HOME/bin/sqlplus -S -M "HTML ON TABLE 'BORDER="2"'" / as sysdba @query.sql > $ORACLE_SID.html
esac # End case $LINE
done
# End Loop read ORATAB

( cat body-message.txt;  uuencode FILE.html FILE.html;) | mail -s "OBIWAN Server Reports"  email@gmail.com -c mail1@gmail.com

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