Pattern from a log within last hour


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pattern from a log within last hour
# 1  
Old 08-07-2013
Bug Pattern from a log within last hour

I want to extract a pattern from a log file within last hour.

I am doing
Code:
grep "pattern" filename | tail -1

It gives the last latest pattern but not within last hour.

and if the pattern found in last hour, output success or else failure.

Last edited by Franklin52; 08-08-2013 at 03:24 AM.. Reason: Please use code tags
# 2  
Old 08-07-2013
We need the format of the log - a sample will be good.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 08-07-2013
Code:
[8/5/13 9:50:45:456 EDT] CBWIJO1: error occured while connecting to server.
[8/5/13 9:50:46:123 EDT] CBWIJ15: check for database connection.

this is just a sample.
I need to find the for pattern "error" within last hour. and if it found echo found else not found.

Last edited by Franklin52; 08-08-2013 at 03:24 AM.. Reason: Please use code tags
# 4  
Old 08-08-2013
This may need some tweak to work for you
Code:
# Getting the data for last hour
data_1h=$(awk '$0>=from && $0<=to' from="$(date +"["%D" "%H:%M%S -d -1hour)" to="$(date +"["%D" "%H:%M%S )" logfile)
# finding error and print
echo "$data_1h" | grep "error"

This User Gave Thanks to Jotne For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

2. Shell Programming and Scripting

Grep in a log file within a time range (hour)

Hi, im trying to write a grep script that returns me the last inputs added in the last hour in the log file. Literally i have nothing yet but: grep 'Line im looking for' LOGFILE.log | tail -1 this only gives me the last input, but no necessarily from the last hour. Help Please. (4 Replies)
Discussion started by: blacksteel1988
4 Replies

3. Shell Programming and Scripting

Pick the last one hour lines from log matching this pattern.

Hello please help me on this, pick the last one hour lines from the log, which have the prefix time format like this. log message log message i tried to do grep, but that failed. my code grep '(date +)' log_file_path This checking only the current time stamp. How to get the log... (16 Replies)
Discussion started by: santosh2626
16 Replies

4. Shell Programming and Scripting

Parsing and timestamp a pattern in log

Hello Thanks to Chubler_XL and MadeInGermany for their help few weeks ago. Now, i would like modifying the script, see the next POST. The old script works like that : I picked any random hours In the logs there is the stamp time of webservices, i can see the behavior or errors of... (3 Replies)
Discussion started by: amazigh42
3 Replies

5. Shell Programming and Scripting

Write Log per hour

Hi, the follow can add the day time to my Log file My_Log_$(date +%F).log can I add the hour to the end of my log file then my log file will looks like My_Log_07-24:(:confused: (3 Replies)
Discussion started by: Hscript
3 Replies

6. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

7. Shell Programming and Scripting

Calculate total of log by hour

Hi, Just wondering, is there anyway I can get the total of logs generated by hours ? Let say I have these logs, Sep 23 04:48:43 hsbcufs: NOTICE: realloccg /: file system full Sep 23 04:48:47 hsbcufs: NOTICE: alloc: /: file system full Sep 23 04:48:51 hsbcufs: NOTICE: realloccg /: file... (14 Replies)
Discussion started by: dehetoxic
14 Replies

8. Shell Programming and Scripting

Getting the last hour from a log.

I have a log like this: Jan 26 13:59:41 server2 ntpdate: step time server 91.189.94.4 offset 0.065456 sec Jan 26 13:59:41 server2 ntpd: ntpd 4.2.4p8@1.1612-o Fri Aug 6 22:49:54 UTC 2010 (1) Jan 26 13:59:41 server2 ntpd: precision = 1.000 usec Jan 26 13:59:41 server2 ntpd: ntp_io: estimated max... (2 Replies)
Discussion started by: Jotne
2 Replies

9. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

10. UNIX for Dummies Questions & Answers

an hour less in 24 hour system

My program: __________________________________ #!/bin/ksh DAY=`date +%y%m%d` H=`date +%H` M=`date +%M` day=`date +%m/%d/%y` let h=$H-1 echo DAY $DAY echo H $H echo M $M echo day $day echo h $h _____________________________________ My result: (3 Replies)
Discussion started by: bobo
3 Replies
Login or Register to Ask a Question