Hi all u brilient people on the forum...
I am trying to call the variable value in awk command for search pattern /start/,/stop/ but i am nt able to do this ....
wat i did is ..i have created two variable YESTERDAY and TODAY and passed the y'day n 2'days dates in it...like this
YESTERDAY=`TZ=aaa24 date +"%b %d"`
TODAY=`date +"%b %d"`
now am trying call this variable value in awk command which will search the content of the file between Y'days and 2days date and redirect the output to another file ....As this
10x...4 reply to my thread bt
How can i use -v option in awk for /start/,/stop/ search option...
Kanchan
Also my search pattern is the date which will retrieve by the variable which i was defined above....
It has to search the result based on the Yesterdays and todays date.
I was already tried to put in double qoute bt no luck...
10x 4 reply...
bt still its not working..
I think u ddnt undersand my requirement.
Here i want to retrieve the value based on the YESTERDAYS Date and TODAYS date and my script will redirect the content of the file Between yesterdays date and todays date. The file on which i am taking the search is having the daily update mentioning the date format e.g say Apr 16 ,Apr 15,Apr 14 like that. so if i pass the value Apr 15 in place of YESTERDAY variable and Apr 16 for TODAYS then it has to give the content of the file between these two dates.
i am using awk command of search string '/START/,/STOP/' where START if 4 YESTERDAY and STOP 4 TODAY... and the syntax which awk command use for this kind of search is shown above in colored..
So here i have already defined the variable YESTERDAY and TODAY...
My problem is how to pass the value for both the variable.....
My code is some what like this
YESTERDAY=`TZ=aaa24 date +"%b %d"`
TODAY=`date +"%b %d"`
echo $TODAY
echo $YESTERDAY
awk '/"$YESTERDAY {print}"/,/"$TODAY {print}"/' $HOME/alert_out.log >> $HOME/alert_work.log
but here its not passing the value 4 both variables though its still creating the file $HOME/alert_work.log but with zeor content.
-------here is my code which i have written (for bottleneck look at the code RED)------
#!/bin/ksh
for SID in `cat $HOME/appleora/dblist`
do
cd $HOME/appleora/$SID/admin/bdump
cat alert_${SID}.log >>$HOME/alert_${SID}.log
cd
if [ -f alert_${SID}.log ]
then
mv alert_${SID}.log alert_out.log
touch alert_${SID}.log
YESTERDAY=`TZ=aaa24 date +"%b %d"`
TODAY=`date +"%b %d"`
echo $TODAY
echo $YESTERDAY
#awk '/Apr 15/,/Apr 16/' $HOME/alert_out.log >> $HOME/alert_work.log
#awk '/$YESTERDAY/,/$TODAY/' $HOME/alert_out.log > $HOME/alert_work.log
awk -v var=$YESTERDAY,var1=$TODAY '$0~var,$0~var1' $HOME/alert_out.log > $HOME/alert_work.log
cat alert_work.log >> alert_${SID}.hist
grep ORA- alert_work.log >> alert.err
fi
for DBA in `cat $HOME/appleora/dbalist`
do
if [ `cat alert.err|wc -l` -gt 0 ]
then
mailx -s "${SID} ORACLE ALERT ERRORS" $DBA < alert.err
else
mailx -s "${SID} ORACHECK RUN SUCCESFULLY NO ERROR" $DBA
fi
done
rm -f alert.err
rm -f alert_work.log
done
Now
-----Here is my $HOME/alert_out.log file on which i am doing search and i am intreested in content between Apr 15 and Apr 16----
Wed Apr 15 09:37:05 2009
Thread 1 advanced to log sequence 46
Current log# 3 seq# 46 mem# 0: C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO03.LOG
Wed Apr 15 22:00:14 2009
Thread 1 advanced to log sequence 47
Current log# 1 seq# 47 mem# 0: C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO01.LOG
b_recovery_file_dest_size of 2048 MB is 0.00% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup
Errors in file c:\oracle\product\10.2.0\admin\orcl\udump\orcl_ora_5388.trc:
ORA-00600: internal error code, arguments: [LibraryCacheNotEmptyOnClose], [], [], [], [], [], [], []
Thu Apr 16 09:30:56 2009
that means o/p should be in green
=====================================
Now if i use
#awk '/Apr 15/,/Apr 16/' $HOME/alert_out.log >> $HOME/alert_work.log
then i am getting desired output as well as i am getting mail thru mailx command
=====================================
=====================================
if i use
#awk '/$YESTERDAY/,/$TODAY/' $HOME/alert_out.log > $HOME/alert_work.log
then this file is get created > $HOME/alert_work.log this file bt with no content
=====================================
=====================================
and if i use
awk -v var=$YESTERDAY,var1=$TODAY '$0~var,$0~var1' $HOME/alert_out.log > $HOME/alert_work.log
as u suggested......
i am getting below message
sh oracheck.sh
Apr 16
Apr 15
awk: syntax error near line 1
awk: bailing out near line 1
=====================================
the ' oracheck.sh ' errors have nothing to do with the question you're asking originally - check the $PATH .
As far as 'awk' errors are concerned - as always, if you're on Solaris, use either /usr/bin/nawk or /usr/xpg4/bin/aw k instead of plain old '/usr/bin/awk '.
Good luck.