please help on this


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting please help on this
# 1  
Old 07-21-2008
please help on this

Hi
Previously i've asked in this forum but i cant solve this
This is the contents of file name rman_status.ksh:

sqlplus "/as sysdba" @rman_error.sql > rman_error.txt
mailx -r oraadm@juwpkl.gov.my -c adzuan@nc.com.my -s "RMAN Error" adzuan@nc.com.my < rman_error.txt

contents of rman_error.txt
-------------------------

SQL*Plus: Release 10.2.0.3.0 - Production on Mon Jul 21 17:49:13 2008
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
START_TIME END_TIME STATUS
---------- --------- -----------------------
14-JUL-08 14-JUL-08 COMPLETED WITH ERRORS
21-JUL-08 21-JUL-08 FAILED
19-JUL-08 19-JUL-08 COMPLETED WITH ERRORS
20-JUL-08 20-JUL-08 COMPLETED WITH ERRORS
20-JUL-08 20-JUL-08 FAILED
21-JUL-08 21-JUL-08 COMPLETED WITH ERRORS
19-JUL-08 19-JUL-08 FAILED
7 rows selected.
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
--------------------------------------------------------------------------

Basically i can email the file rman_error.txt BUT i dont want this email alert to be email everyday. I just want mailx email to me when the status of backup is
COMPLETED WITH ERRORS or FAILED.....

Can somebody help me on how to create the script so i can accomplish this??Smilie
# 2  
Old 07-21-2008
Please read forum rules before posting threads.... keep your subject informative so someone will get some idea about your problem. Smilie

Now come to your question ----
1. Get the output and parse it for ERROR's or FAILED Strings.
2. if strings found then mail ..... otherwise dont mail.

hints -
- Use grep to search for strings.
- if condition with -z to check for empty string and accordingly send mail.


- nilesh
# 3  
Old 07-21-2008
Hi Ynilesh
Tq for alerting me
by the way, can u show me how to use that grep command
when i issue this:
bash-3.00$ more rman_error.txt|grep "ERROR"
14-JUL-08 14-JUL-08 COMPLETED WITH ERRORS
19-JUL-08 19-JUL-08 COMPLETED WITH ERRORS
20-JUL-08 20-JUL-08 COMPLETED WITH ERRORS
21-JUL-08 21-JUL-08 COMPLETED WITH ERRORS
How to use grep command so i can show "FAILED" status as well?

Then, after grep is done, how to read from that grep so email will trigger when status COMPLETED WITH ERRORS or FAILED detected?

Appreciate if u can assist....
# 4  
Old 07-21-2008
Assuming you got you output in error.txt and storing that "failed" string output in filename_with_error file.

strings error.txt | grep -i "failed" > filename_with_error
if [ ! -s "filename"]
then
echo "No error found."
else
echo "Sending mail."
mailx -r oraadm@juwpkl.gov.my -c adzuan@nc.com.my -s "RMAN Error" adzuan@nc.com.my < filename_with_error
fi

exit 0

Hope this will work for u.
# 5  
Old 07-21-2008
Hi Ynilesh

It was awsome...

I managed to run that script and this is the output from mail that i received:

21-JUL-08 21-JUL-08 FAILED
20-JUL-08 20-JUL-08 FAILED
19-JUL-08 19-JUL-08 FAILED

Much obliged in advance....if i can get the the column name it will be much more awsome....

Can i get the output like this :

START_TIME END_TIME STATUS
---------- --------- -----------------------
21-JUL-08 21-JUL-08 FAILED
20-JUL-08 20-JUL-08 FAILED
19-JUL-08 19-JUL-08 FAILED
# 6  
Old 07-21-2008
Yes you can do that.....
Check rewamped script,

echo "START_TIME END_TIME STATUS" >> /tmp/filename_with_error
echo "---------- --------- -----------------------" >> /tmp/filename_with_error

strings error.txt | grep -i "failed" >> /tmp/filename_with_error
if [ ! -s "/tmp/filename_with_error"]
then
echo "No error found."
else
echo "Sending mail."
mailx -r oraadm@juwpkl.gov.my -c adzuan@nc.com.my -s "RMAN Error" adzuan@nc.com.my < /tmp/filename_with_error
fi

# Erasing content of temporary file.
unlink /tmp/filename_with_error

exit 0

Let me know if this doesnt work. Smilie

- nilesh
# 7  
Old 07-22-2008
Computer

Hi Ynilesh

Awesome....work successfully

Thanks a lot dude.....

But i will delete this line :

echo "No error found."
else
echo "Sending mail."

So it wont echo any message when i run this command

By the way, may i know certain command function. Example:
what is the meaning of this command - [ ! -s "/tmp/filename_with_error"]
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question