Searching Error Message from a log life between timestamp of every 10 minutes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching Error Message from a log life between timestamp of every 10 minutes
# 1  
Old 12-18-2013
Searching Error Message from a log life between timestamp of every 10 minutes

HI Everyone,

My task is to search error messages last 10 minutes everytime from a log file.


My script,
Code:
date1=`date -d '10 minutes ago' "+%H:%M:%S"`
date2=`date "+%H:%M:%S"`
awk -v d1="${date1}" -v d2="${date2}" '$0~d1{p=1} $0~d2{p=0} p' filename

No error getting in syntex,but nothing is displaying(no output)Smilie
Can anyone help me find the write solution pls.Smilie
Thanks in advanceSmilie

---------- Post updated at 06:26 PM ---------- Previous update was at 05:56 PM ----------

Code:
if [ $2>="$(date -d '45 minutes ago' "+%H:%M:%S")" ];
then 
echo "found"
{print $0}
else 
echo " not found"
fi < filename


output:
Code:
not found:(



can anyone help me soon...with ur valuable ideas

Last edited by Don Cragun; 12-19-2013 at 02:31 AM.. Reason: Font and Size changes deleted; CODE tags added.
# 2  
Old 12-19-2013
Could you please post part of error message ?
# 3  
Old 12-19-2013
Quote:
Originally Posted by ctscbe
HI Everyone,

My task is to search error messages last 10 minutes everytime from a log file.


My script,
Code:
date1=`date -d '10 minutes ago' "+%H:%M:%S"`
date2=`date "+%H:%M:%S"`
awk -v d1="${date1}" -v d2="${date2}" '$0~d1{p=1} $0~d2{p=0} p' filename

No error getting in syntex,but nothing is displaying(no output)Smilie
Can anyone help me find the write solution pls.Smilie
Thanks in advanceSmilie

---------- Post updated at 06:26 PM ---------- Previous update was at 05:56 PM ----------

Code:
if [ $2>="$(date -d '45 minutes ago' "+%H:%M:%S")" ];
then 
echo "found"
{print $0}
else 
echo " not found"
fi < filename


output:
Code:
not found:(



can anyone help me soon...with ur valuable ideas
In your first example, you are looking for timestamps that are exactly 10 minutes ago OR now; not the range of timestamps between those two timestamps, inclusive.

Without seeing sample input, it is hard to imagine getting the output you're showing from your second example, but you are missing required spaces in your if statement:
Code:
if [ $2>="$(date -d '45 minutes ago' "+%H:%M:%S")" ]

needs to be changed to:
Code:
if [ $2 >= "$(date -d '45 minutes ago' "+%H:%M:%S")" ]

or, even better:
Code:
if [ "$2" >= "$(date -d '45 minutes ago' "+%H:%M:%S")" ]

# 4  
Old 01-16-2014
Thanks Pravin 27 and Don Cragon for your valuable replies.Smilie.
I got my requirement by using Pravin27 's reply in some other Forums.Thanks!Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to get last 15 minutes timestamp and threshold > 60 will sent alert?

Hi All, need your help , i have some files and got some below condition cat tdr12009.log | grep -i success | grep promo | awk -F'' '{print substr($1,1,16),$15}' | more 2019-10-16 00:03 delta=1 2019-10-16 00:03 delta=2 2019-10-16 00:04 delta=20 2019-10-16 00:09 delta=10 2019-10-16... (5 Replies)
Discussion started by: fajar_3t3
5 Replies

2. Shell Programming and Scripting

Grep a log file for the last 5 minutes of contents every 5 minutes

Hi all, System Ubuntu 16.04.3 LTS i have the following log INFO 2019-02-07 15:13:31,099 module.py:700] default: "POST /join/8550614e-3e94-4fa5-9ab2-135eefa69c1b HTTP/1.0" 500 2042 INFO 2019-02-07 15:13:31,569 module.py:700] default: "POST /join/6cb9c452-dcb1-45f3-bcca-e33f5d450105... (15 Replies)
Discussion started by: charli1
15 Replies

3. UNIX for Beginners Questions & Answers

Searching exception keyword in all logs in last 5 minutes

Hello Folks , I am a new bie to the world of unix , what i am planning to do is the I have the location in server to which i am access through the putty and the location is /mt/ttlog/avccomn/logs/201901/19 and at this location the files are listed as show startjmsnode1.sh_03.out... (7 Replies)
Discussion started by: punpun26262626
7 Replies

4. UNIX for Beginners Questions & Answers

How to convert days hours minutes seconds to minutes?

Hi, please help with below time conversion to minutes. one column values: 2 minutes 16 seconds 420 msec 43 seconds 750 msec 0 days 3 hours 29 minutes 58 seconds 480 msec 11 seconds 150 msec I need output in minutes(total elapsed time in minutes) (2 Replies)
Discussion started by: ramu.badugula
2 Replies

5. Shell Programming and Scripting

Capture all error message in Log file and send the Log file by email

Hi I have a requirement to write a script to capture all errors in a Logfile and send the file in email. If there is any error occurred the subject of email will be ERROR , If there are no error occurred the subject of email will be SUCCESS. So I created a Log file and put the Appropriate... (2 Replies)
Discussion started by: dgmm
2 Replies

6. UNIX for Advanced & Expert Users

End of Life / Life Cycle Information

Hello everyone, I was searching for locations where I can get End of Life information on multiple versions of Unix. I have found some information which I list below, what I have not found or confirmed is where I can get the information for: DEC Unix/OSF1 V4.0D NCR Unix SVR4 MP-RAS Rel 3.02.... (2 Replies)
Discussion started by: robertmcol
2 Replies

7. Shell Programming and Scripting

Fishing out error message within a log file

Hi all, i have a log file that captures success or failure messges when i run a daily job. here is a sample of my log. 20060312 start successful successful failure failure 20060312 end i need to write a subroutine that opens up the log daily after my job completes to examine the log... (2 Replies)
Discussion started by: new2ss
2 Replies

8. UNIX for Advanced & Expert Users

Append error message to the log

In my unix system , I chceck that there are error message append to the /var/adm/syslog . But I also found that part of these message will pop to my login session ( I use telent to login to server ) , I also check the /var/mail/my_loginid is empty , could suggest how can I forbid the message pop to... (1 Reply)
Discussion started by: ust
1 Replies
Login or Register to Ask a Question