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