Tag Archives: Unix Shell Script

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

By raja_dba

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 generated alert log.

I wanted to extract the ORA errors generated yesterday. ( APR 15 )

I was trying this,

===================================

SCRIPT

cd /back/alert/log
a=`date ‘+%b %d’ -d “yesterday”`
b=`date ‘+%b %d’`
c=”$a $b”
echo “$c”
awk “/$1 $2/,/$3 $4/” alert_dbname.log | sed ‘$d’
exit

=================================================

echo “$c” would output yesterday’s date and today’s date in the format

Apr 15 Apr 16

And from here I want to substitute the Apr 15 Apr 16 in awk as

[[[ awk ‘/Apr 15/,/Apr 16/’ alert_dbname.log | sed ‘$d’ | grep ORA ]]]]

And for this substitution I have written in the script

awk “/$1 $2/,/$3 $4/” alert_dbname.log | sed ‘$d’

But this doesn’t bring me the required output.

Could you please help me working on this script?

Thanks,
Raja

From: http://www.unix.com/shell-programming-scripting/221219-extracting-sysdate-1-ora-errors-can-you-help-me-unix-script.html