LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Query on shell script (https://www.linuxquestions.org/questions/linux-newbie-8/query-on-shell-script-4175473547/)

manickaraja 08-15-2013 07:46 PM

Query on shell script
 
Hi,
I have a requirement to scan Oracle's alert log file. This file logs all event for Oracle database and each line will have timestamp followed by messages (which might be one or more lines).
Example.
Thu Aug 15 17:35:59 2013
VKTM detected a time drift. Please check trace file for more details.

I have a requirement to scan this log to fine last 5 minutes worth of data entered on this. Could you please help me with the same.

Thanks in advance for your help.

Thanks,
Manick.

TB0ne 08-15-2013 08:27 PM

Sure, we'll be glad to help. So post what you've written so far. But we're not going to write your scripts for you.

Firerat 08-15-2013 08:46 PM

date --date="5 min ago"

you may need to play around with the output format
man date
for details

then you could just grep that date, with a silly 'after' ( -A 5000 )

Code:

FiveMinAgo="$(date +"%b %d %H:%M" --date="5 min ago")
SixMinAgo="$(date +"%b %d %H:%M" --date="6 min ago")

grep -A 5000 "${FiveMinAgo}" /path/to/log.log || grep -A 5000 "${SixMinAgo}" /path/to/log.log

don't know how often that log is written to ;)
You may need to be 'smarter'
but you have something to work with ( don't expect the above to be fool proof, it isn't )


All times are GMT -5. The time now is 10:16 AM.