Shell script to capture ORA errors from Alert Log


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to capture ORA errors from Alert Log
# 1  
Old 06-07-2011
Shell script to capture ORA errors from Alert Log

Hi,

as the title says, I am after a simple script, which will open the Alert log from
an 11.2.0.1 Linux environment and mail the error message and description to a recipient email address.

I can then schedule this job via cron and let it run every 15 minutes.

I have searched online for this - but many of them seem either too complex or
do not work for Oracle 11

Thanks for your assistance
# 2  
Old 06-07-2011
Why not submit a sample of each ( too complex, not working with oracle 11), so that we can do some brainstorming, for the benefit of all?
First case would be to understand the complexity and simplify to suit your plan.
Second, to see if the issue can be solved...
# 3  
Old 06-07-2011
OK, thanks,

I have this particular script, which I have executed - but nothing is extracted from the alert log and therefore no mail is sent.
Can you have a scan through this script and tell me if there any errors - or am I able to schedule this via cron

script:

Code:
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."


Last edited by Franklin52; 06-07-2011 at 06:20 AM.. Reason: Please use code tags and indentation
# 4  
Old 06-07-2011
What does adrci in the line
Code:
adrci << EOF

do?
# 5  
Old 06-07-2011
adrci - is the new 11g feature that reads the alert log

Automatic Diagnostic Repository Command Interface
# 6  
Old 06-07-2011
Something like this should work with bash:

Code:
#!/bin/bash


ORACLE_HOME=<your_oracle_home>
ORACLE_SID=<your_oracle_sid>
ORAENV_ASK=NO
export ORACLE_HOME ORACLE_SID ORAENV_ASK
_my_first_date='1990-01-01 00:00:00'
_my_last_date_file=_my_last_date

[ -f "$_my_last_date_file" ] ||
  printf > ./"$_my_last_date_file" '%s\n' "$_my_first_date"
  
_last_date=$(<./"$_my_last_date_file")

printf > ./"$_my_last_date_file" '%s\n' "$(
  date '+%Y-%m-%d %H:%M:%S'
  )"

_mailto=<your_email_address>
_mail_subject="Alert for $ORACLE_SID on $HOSTNAME"


_my_result=$(
  adrci exec="
    set home $ORACLE_SID;
    show alert -term -P \\\"MESSAGE_TEXT like '%ORA%' and ORIGINATING_TIMESTAMP >= '$_last_date'\\\"
   "
  )

case $_my_result in 
  ( *ORA-* ) mailx -s "$_mail_subject" "$_mailto" <<< "$_my_result"  
esac


Last edited by radoulov; 06-07-2011 at 06:09 PM..
# 7  
Old 06-08-2011
Hi,

Thanks for that and I executed the script and these are the results.
Maybe something is not enabled, prior to execution. This was run from the command line, not from cron


Code:
[oracle@ukedxdtmtdbs01a bin]$ #!/bin/bash
[oracle@ukedxdtmtdbs01a bin]$
[oracle@ukedxdtmtdbs01a bin]$
[oracle@ukedxdtmtdbs01a bin]$ ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
[oracle@ukedxdtmtdbs01a bin]$ ORACLE_SID=DCTMTEST1
[oracle@ukedxdtmtdbs01a bin]$ ORAENV_ASK=NO
[oracle@ukedxdtmtdbs01a bin]$ export ORACLE_HOME ORACLE_SID ORAENV_ASK
[oracle@ukedxdtmtdbs01a bin]$ _my_first_date='1990-01-01 00:00:00'
[oracle@ukedxdtmtdbs01a bin]$ _my_last_date_file=_my_last_date
[oracle@ukedxdtmtdbs01a bin]$
[oracle@ukedxdtmtdbs01a bin]$ [ -f "$_my_last_date_file" ] ||
>   printf > ./"$_my_last_date_file" '%s\n' "$_my_first_date"
-bash: ./_my_last_date: Permission denied
[oracle@ukedxdtmtdbs01a bin]$
_l[oracle@ukedxdtmtdbs01a bin]$ _last_date=$(<./"$_my_last_date_file")
-bash: ./_my_last_date: No such file or directory
[oracle@ukedxdtmtdbs01a bin]$
p[oracle@ukedxdtmtdbs01a bin]$ printf > ./"$_my_last_date_file" '%s\n' "$(
>   date '+%Y-%m-%d %H:%M:%S'
 >   )"
-bash: ./_my_last_date: Permission denied
[oracle@ukedxdtmtdbs01a bin]$
_m[oracle@ukedxdtmtdbs01a bin]$ _mailto=name@company.com
[oracle@ukedxdtmtdbs01a bin]$ _mail_subject="Alert for $ORACLE_SID on $HOSTNAME"

[oracle@ukedxdtmtdbs01a bin]$ _my_result=$(
>   adrci exec="
>     set home $ORACLE_SID;
>     show alert -term -P \\\"MESSAGE_TEXT like '%ORA%' and ORIGINATING_TIMESTAMP >= '$_last_date'\\\"
>    "
>   )
[oracle@ukedxdtmtdbs01a bin]$
[oracle@ukedxdtmtdbs01a bin]$ case $_my_result in
 >   ( *ORA-* ) mailx -s "$_mail_subject" "$_mailto" <<< "$_my_result"
> esac
[oracle@ukedxdtmtdbs01a bin]$


Last edited by radoulov; 06-08-2011 at 04:40 AM.. Reason: Code tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check for “errors” or “ORA-”

I want to check for "errors" or "ORA-" in Y.if there is an error then exit Y=`sqlplus -s user/passwd<< EOF exec test_Proc; exit; EOF` if ; then exit 1 fi but this doesnt work (6 Replies)
Discussion started by: haadiya
6 Replies

2. Shell Programming and Scripting

Shell script to capture Current day ORA errors from Alert Log

Please provide Shell script to capture ORA errors from Alert Log for a given date or Current date. -Veera (1 Reply)
Discussion started by: Veera_V
1 Replies

3. Shell Programming and Scripting

Extracting Sysdate-1 ORA Errors - Can you help me in this UNIX Script?

Hi Guys, I wanted to create an Unix Shell Script that should fetch a particular string from a text file on a particular date. We all know Oracle generates alert logs for each and every day for every actions in the database. I have an alert log file now where it contains for about a months... (4 Replies)
Discussion started by: raja_dba
4 Replies

4. Shell Programming and Scripting

How to turn off ora errors in shell script?

I have a shell script which select total count from a table and use its value in a if condition like below connect_string="username/password@tnsname" tot=`sqlplus -s $connect_string << EOF set echo off set feedback off set head off select count(*) from test_table; EOF ` if then echo... (2 Replies)
Discussion started by: vel4ever
2 Replies

5. Shell Programming and Scripting

Capture makefile errors in shell script

Hi, I have a bash script which calls a few "make". I would like to know whether the makefile failed with any errors. How do I do that in the script? Thanks, S (2 Replies)
Discussion started by: suryaemlinux
2 Replies

6. UNIX for Advanced & Expert Users

grep all ORA errors except one ORA error

Hi - I am trying to grep all "ORA" errors in a log files.I have to grep all ORA errors except one error for example ORA-01653.How can exclude that error in "grep" command? In following "grep" command I want to exclude "ORA-01653" error grep -i ORA alert.log >>/tmp/ora_errors.txt ... (7 Replies)
Discussion started by: Mansoor8810
7 Replies

7. Shell Programming and Scripting

Script to capture date/time in seconds in PERL... Cant understand errors

I'm Using this script to find the time of a file. I'm very much new to PERL and found this script posted by some one on this forum. It runs perfectly fine, just that it gives me following errors with the accurate output as well. I jus want the output to be stored in another file so that i can... (0 Replies)
Discussion started by: bankimmehta
0 Replies

8. Shell Programming and Scripting

Need to capture the service name from tnsnames.ora and create connect string

ghkjkjoj (4 Replies)
Discussion started by: chetankelvin
4 Replies

9. Shell Programming and Scripting

Script to capture errors

Hello; I'm trying to write a script to capture any hardware error from logs/syslog on my SUSE 10 servers so i can be notified if we have any hardware issues such a bad fan or battery, etc.. Thanks in advance for any help (2 Replies)
Discussion started by: Katkota
2 Replies

10. Shell Programming and Scripting

How to get ORA errors in alertlog file using shell script.

Hi, Can anyone tell me how to get all ORA errors between two particular times in an alertlog file using shell script. Thanks (3 Replies)
Discussion started by: suman_dba1
3 Replies
Login or Register to Ask a Question