Need to get all the records from a log file greater than timestamp supplied.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to get all the records from a log file greater than timestamp supplied.
# 1  
Old 04-20-2013
Need to get all the records from a log file greater than timestamp supplied.

I have a log file which has records with hung thread information/error
I need to find out hung thread from log file greater than timestamp supplied.

Code:
[4/19/13 0:49:32:250 EDT] 00000026 ThreadMonitor W   WSVR0605W: Thread "WebContainer : 1" (00000027) has been active for 701879 milliseconds and may be hung.  There is/are 1 thread(s) in total in the server that may be hung.

[4/19/13 02:49:32:270 EDT] 00000026 ThreadMonitor W   WSVR0605W: Thread "WebContainer : 0" (00000025) has been active for 703210 milliseconds .  There is/are 2 thread(s) in total in the server.
[4/19/13 03:49:32:250 EDT] 00000026 ThreadMonitor W   WSVR0605W: Thread "WebContainer : 1" (00000027) has been active for 701879 milliseconds.  There is/are 1 thread(s) in total in the server .

[4/19/13 05:44:32:270 EDT] 00000026 ThreadMonitor W   WSVR0605W: Thread "WebContainer : 0" (00000025) has been active for 703210 milliseconds and may be hung.  There is/are 2 thread(s) in total in the server that may be hung.
[4/19/13 05:41:32:250 EDT] 00000026 ThreadMonitor W   WSVR0605W: Thread "WebContainer : 1" (00000027) has been active for 701879 milliseconds and may be hung.  There is/are 1 thread(s) in total in the server that may be .

[4/19/13 06:49:32:270 EDT] 00000026 ThreadMonitor W   WSVR0605W: Thread "WebContainer : 0" (00000025) has been active for 703210 milliseconds and may be hung.  There is/are 2 thread(s) in total in the server that may be hung.


Last edited by Scrutinizer; 04-20-2013 at 06:29 AM.. Reason: code tags
# 2  
Old 04-20-2013
What format do you want to use for the timestamp? What have you tried?
# 3  
Old 04-20-2013
Below is the date format of the timestamp to be passed as parameter.

4/19/13 02:49:32
# 4  
Old 04-20-2013
In overall terms:
Code:
- Using date command, convert timestamp_supplied to seconds_since_epoch.
- For each line in log file (while read):
  - Use cut or sed to get date_field.
  - Using date command, convert date_field to seconds_since_epoch.
  - Use test command to determine which seconds_since_epoch is larger.

# 5  
Old 04-20-2013
It could be done without the date command and epoch time. Try:
Code:
awk -F'[][]' -v t="4/19/13 02:49:32" '
  function ts(t,    T){
    split(t,T,/[\/ :]/)
    return sprintf("%02d%02d%02d%02d%02d%02d",T[3],T[1],T[2],T[4],T[5],T[6])
  }
  # If the line is not empty and the timestamp is greater than or equal to the reference timestamp
  NF && ts($2)>=ts(t)
' file


Last edited by Scrutinizer; 04-20-2013 at 05:50 PM..
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 04-22-2013
It is giving a syntax error near line 1

---------- Post updated at 04:13 AM ---------- Previous update was at 03:49 AM ----------

I tried the below piece of code in ubuntu and it is working fine to fetch the timestamp,but in solaris 5.10 it is not working

Code:
line='[4/19/13 0:49:32:250 EDT] 00000026 ThreadMonitor W   WSVR0605W: Thread "WebContainer : 1" (00000027) has been active for 701879 milliseconds and may be hung.  There is/are 1 thread(s) in total in the server that may be hung.

Code:
echo $line|awk -F"[/ \\\][]" '{print  $5}'

any suggestions

Last edited by radoulov; 04-22-2013 at 06:41 AM..
# 7  
Old 04-22-2013
On Solaris use /usr/xpg4/bin/awk rather than awk
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Filter records from a log file based on timestamp

Dear Experts, I have a log file that contains a timestamp, I would like to filter record from that file based on timestamp. For example refer below file - cat sample.txt Jan 19 20:51:48 mukul-Vostro-14-3468 systemd: pam_unix(systemd-user:session): session opened for user root by (uid=0)... (6 Replies)
Discussion started by: mukulverma2408
6 Replies

2. Shell Programming and Scripting

Changing information supplied when running file

In unix systems I can call `file` to return me the file type. file cel.vik $ cel.vik: ASCII text How can I append additional information when I create a file such that when I call `file` it returns me that additional information. (2 Replies)
Discussion started by: kristinu
2 Replies

3. Shell Programming and Scripting

prepend timestamp to continiously updating log file

Hi, I have a process which outputs to a log. Below is the code snippet: process &> $LOGFILE& The log file keeps on updating whenever a transaction is processed. The log file has a time stamp added so every time I kill the process and start the process a new log file is... (4 Replies)
Discussion started by: rajkumarme_1
4 Replies

4. Shell Programming and Scripting

Identifying files with a timestamp greater than a given timestamp

I need to be able to identify files with file timestamps greater than a given timestamp. I am using the following solution, although it appears to compare files at the "seconds" granularity and I need it at the milliseconds. When I tested my solution, it missed files that had timestamps... (3 Replies)
Discussion started by: nkm0brm
3 Replies

5. Shell Programming and Scripting

AWK: Cannot read Number of records greater than 1(NR>1)

Hi all, I have a tab-delimited text file of size 10Mb. I am trying to count the number of lines using, grep -c . sample.txtor wc -l < sample.txt or awk 'END {print NR}' sample.txtAll these commands shows the count as 1, which means they are reading only the first header line of the file.... (3 Replies)
Discussion started by: mehar
3 Replies

6. Shell Programming and Scripting

Delete log file entries based on the Date/Timestamp within log file

If a log file is in the following format 28-Jul-10 ::: Log message 28-Jul-10 ::: Log message 29-Jul-10 ::: Log message 30-Jul-10 ::: Log message 31-Jul-10 ::: Log message 31-Jul-10 ::: Log message 1-Aug-10 ::: Log message 1-Aug-10 ::: Log message 2-Aug-10 ::: Log message 2-Aug-10 :::... (3 Replies)
Discussion started by: vikram3.r
3 Replies

7. Shell Programming and Scripting

How to search backwards in a log file by timestamp of entries?

Hello. I'm not nearly good enough with awk/perl to create the logfile scraping script that my boss is insisting we need immediately. Here is a brief 3-line excerpt from the access.log file in question (actual URL domain changed to 'aaa.com'): 209.253.130.36 - - "GET... (2 Replies)
Discussion started by: kevinmccallum
2 Replies

8. Shell Programming and Scripting

concatenate log file lines up to timestamp

Hi, Using sed awk or perl I am trying to do something similar to https://www.unix.com/shell-programming-scripting/105887-sed-awk-concatenate-lines-until-blank-line-2.html but my requirement is slightly different. What I am trying to accomplish is to reformat a logfile such that all lines... (4 Replies)
Discussion started by: AlanC
4 Replies

9. Shell Programming and Scripting

List all log records logged after $timestamp ?

I am trying to find a way to list every records inside a file (usually a log file) that are present after a record mathing/greater-then a timestamp supplied by another script. The timestamp can be anywhere inside the record and it is usually in the standard `date` format (will not look for other... (5 Replies)
Discussion started by: Browser_ice
5 Replies

10. UNIX for Dummies Questions & Answers

Spooling a log file with timestamp

Hi From shell script i am invoking sqlplus to connect to oracle database and then i spool a csv file as with output. What i want to do is to change the file name with timestamp on it so after spooling finish shell script change file name with time stamp. can someone help me to do that . Thanks... (2 Replies)
Discussion started by: ukadmin
2 Replies
Login or Register to Ask a Question