Hi,
I am working on this script, which I want it to open the alert log and email any ORA error messages
================================================== =========
export SID=$ORACLE_SID
export TIMESTAMP=`date +%M%H%d%m%y`;
export mon_dir=$ORACLE_BASE/admin/DCTMTEST/dbmonitor
export fn=$mon_dir/email_body.tmp
export alertck=$mon_dir/alertck.log
touch $alertck*
touch $fn
touch $ORACLE_BASE/admin/DCTMTEST/dbmonitor/donot_delete.log
EMAIL='name@company.com'
adrci << EOF
spool $mon_dir/alert_$TIMESTAMP.log
set termout off
set homepath diag/rdbms/$ORACLE_SID/$ORACLE_SID
SHOW ALERT -P "MESSAGE_TEXT LIKE '%ORA-%'" -term
spool off
exit
EOF
export c_log=`wc -l $mon_dir/alert_$TIMESTAMP.log awk '{ print $1 }'`
export c_tmp=`wc -l $mon_dir/donot_delete.log awk '{ print $1 }'`
echo $c_log
echo $c_tmp
if (($(($c_log)) > $(($c_tmp)))); then
comm -23 $mon_dir/alert_$TIMESTAMP.log $mon_dir/donot_delete.log grep ORA- sort -u > $alertck
exec 3< $alertck
# read until the end of the file
until [ $done ]
do
read <&3 ERR_LINE
if [ $? != 0 ] then
done=1
continue
fi
echo $ERR_LINE >> $fn
export ERR_NO=`echo $ERR_LINE awk '{ print $1 }'awk -F- '{ print $2 }' awk -F: '{ print $1 }'`
echo " Oracle error is : ORA-$ERR_NO"
oerr ora $ERR_NO >> $fn
echo " " >> $fn
echo "-----------------------------------------------------" >> $fn
echo " " >> $fn
'done'
echo "ERRORS: sending mail!"
SUBJECT="$SID - ORA Error Message found in alert.log on `date`"
echo $SUBJECT
# from a Linux server, use following line to send email:
cat $fn mail -s "$SUBJECT" $EMAIL
else
echo "No Oracle error is found in alert.log since last time this script was run."
'fi'
mv $mon_dir/alert_$TIMESTAMP.log $mon_dir/donot_delete.log
rm $fn
echo "The script was executed successfully."
================================================== =======
The output is as follows:-
[oracle@ukedxdtmtdbs01a ~]$ export SID=$ORACLE_SID
[oracle@ukedxdtmtdbs01a ~]$ export TIMESTAMP=`date +%M%H%d%m%y`;
[oracle@ukedxdtmtdbs01a ~]$ export mon_dir=$ORACLE_BASE/admin/DCTMTEST/dbmonitor
[oracle@ukedxdtmtdbs01a ~]$ export fn=$mon_dir/email_body.tmp
[oracle@ukedxdtmtdbs01a ~]$ export alertck=$mon_dir/alertck.log
[oracle@ukedxdtmtdbs01a ~]$ touch $alertck*
[oracle@ukedxdtmtdbs01a ~]$ touch $fn
[oracle@ukedxdtmtdbs01a ~]$ touch $ORACLE_BASE/admin/DCTMTEST/dbmonitor/donot_delete.log
EMAIL=[oracle@ukedxdtmtdbs01a ~]$ EMAIL='name@company.com'
[oracle@ukedxdtmtdbs01a ~]$ adrci << EOF
> spool $mon_dir/alert_$TIMESTAMP.log
> set termout off
s> set homepath diag/rdbms/$ORACLE_SID/$ORACLE_SID
> SHOW ALERT -P "MESSAGE_TEXT LIKE '%ORA-%'" -term
> spool off
> exit
> EOF
ADRCI: Release 11.2.0.1.0 - Production on Mon Jun 6 14:53:38 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
ADR base = "/u01/app/oracle"
adrci> adrci> adrci> adrci> export c_log=`wc -l $mon_dir/alert_$TIMESTAMP.log awk '{ print $1 }'`
export c_tmp=`wc -l $mon_dir/donot_delete.log awk '{ print $1 }'`
echo $c_log
echo $c_tmp
if (($(($c_log)) > $(($c_tmp)))); then
comm -23 $mon_dir/alert_$TIMESTAMP.log $mon_dir/donot_delete.log grep ORA- sort -u > $alertck
exec 3< $alertck
# read until the end of the file
until [ $done ]
do
read <&3 ERR_LINE
if [ $? != 0 ] then
done=1
continue
fi
echo $ERR_LINE >> $fn
export ERR_NO=`echo $ERR_LINE awk '{ print $1 }'awk -F- '{ print $2 }' awk -F: '{ print $1 }'`
echo " Oracle error is : ORA-$ERR_NO"
oerr ora $ERR_NO >> $fn
echo " " >> $fn
echo "-----------------------------------------------------" >> $fn
echo " " >> $fn
'done'
echo "ERRORS: sending mail!"
SUBJECT="$SID - ORA Error Message found in alert.log on `date`"
echo $SUBJECT
# from a Linux server, use following line to send email:
cat $fn mail -s "$SUBJECT" $EMAIL
else
echo "No Oracle error is found in alert.log since last time this script was run."
'fi'
mv $mon_dir/alert_$TIMESTAMP.log $mon_dir/donot_delete.log
rm $fn
echo "The script was executed successfully."
================================================== =======
Can someone confirm that this script is fine. If that is the case and the script is working as it should,
how do I include a line to send an email - stating that there are no errors, and the alert log is fine.
Much appreciated for your feedback