List all log records logged after $timestamp ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List all log records logged after $timestamp ?
# 1  
Old 06-16-2009
Question 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 formats).

ex:
Tue Jun 16 03:47:58 EDT 2009

I thought of using awk (on client's AIX 4.2) with index(str,regex) but that function does not see any timestamps inside the records (copied code below from memory).

awk -F" " '{
WHICHPOS=index($0,"[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9] * 20[0-9][0-9]")

if ( WHICHPOS > 0) print WHICHPOS, NR, $0
}' /tmp/a_file



At first the * was producting verry odd results (was replaced by content of `ls *`). So I removed the " * 20[0-9][0-9]" part.

But then, it never sees any timestamp (I checked the file content).

I am beginning to wonder what kind of regular expression that index() can take.

Is there a timestamp pattern available in regular expressions ?
# 2  
Old 06-16-2009
use code tags
then share your input file with more records...
code you are trying
and expected output...
# 3  
Old 06-16-2009
Quote:
Originally Posted by rakeshawasthi
use code tags
then share your input file with more records...
code you are trying
and expected output...
To me, what you are saying does not make sense.
# 4  
Old 06-16-2009
Its okay.. I just wanted you to use code tags and show me the output you wanted with the sample of input records. Smilie
# 5  
Old 06-16-2009
Quote:
Originally Posted by rakeshawasthi
Its okay.. I just wanted you to use code tags and show me the output you wanted with the sample of input records. Smilie
I have no direct way of putting here file samples. All the files I want to use this method all have different formats, different infos but all have standard `date` format infos. The current file I am testing has records looking like :

Quote:
xxxxxxxxxxxxxxxx Sat May 16 19:30:28 EDT 2009.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxx

xxxxxxxxxxxxxxxx Sat May 16 23:30:14 EDT 2009.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxx

...

where 'xxxxxxxxxx' is anything.
As for the code tags, if you mean using clear coding methods, I was just doing a quick test to see if it is feasible. Cleaner code would come next if it works.
# 6  
Old 06-16-2009
try this
Code:
WHICHPOS=match($0,"[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [A-Z][A-Z][A-Z] 20[0-9][0-9]")

PS:- By using code tags, I meant putting [code] around your code, like I have done just now.
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

How to show a list of currently logged in and logging out users?

Hi Guys! I am sure that this question might appeared previously, but I still don't know how to show a list of logged out users. Please help with this! Thanks in advance:) (5 Replies)
Discussion started by: saloliubliu
5 Replies

3. Shell Programming and Scripting

(RHEL, Bash) List users and check if they have logged on during the last 2 months

Hi everyone, At work we were told to check the list of users of an application server and delete all those that have left the company or don't need access to the application anymore. Here's what I came up with. Would you be as kind as to tell me your opinion and whether there is a faster / easier... (4 Replies)
Discussion started by: gacanepa
4 Replies

4. Shell Programming and Scripting

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. 00000026 ThreadMonitor W WSVR0605W: Thread "WebContainer : 1" (00000027) has been active for 701879 milliseconds and may be hung. There is/are... (6 Replies)
Discussion started by: megh
6 Replies

5. Shell Programming and Scripting

Need expect to read variables from a list while logged into the same device

Hi, I'm primarily a Cisco/Juniper networking guy, so you'll have to forgive my ignorance when it comes to scripting (although I do write simple backup scripts and things of that nature on a regular basis and I run Linux at home, so I am vaguely familiar with it). What I need to do should be... (2 Replies)
Discussion started by: wolverene13
2 Replies

6. Programming

Get the list of logged in users

How can I get the list of logged in users in the system programmatically? I can get the list with 'who' or 'users' commands but I need to get the list programmatically... May someone help, please? Thanks in advance. (2 Replies)
Discussion started by: xyzt
2 Replies

7. UNIX for Dummies Questions & Answers

How to do a login time and date list of users never logged on?

Hello, I'm trying to do a list of user that never connected to a couple of servers. I want to do a diff between the servers lists, and print out only the users that never has logged on each server. Here my first step : SERVER01: # finger `egrep -v -e "^\s*#" /etc/passwd | awk '{ print $1 }' |... (4 Replies)
Discussion started by: gogol_bordello
4 Replies

8. Solaris

List all inactive users who has not logged on since last 90 days

I need actuall script which List all inactive users who has not logged on since last 90 days Thanks in advance. Di! (17 Replies)
Discussion started by: haridham
17 Replies

9. UNIX for Dummies Questions & Answers

List all inactive users who has not logged on since last 90 days

Hi, Can I get a script to list out all the users, who has not logged on since last 90 days. Last command in not working due due to /var/adm/wtmpx is more than 2 GB. Thanks in advance. Regards, Roni (10 Replies)
Discussion started by: manasranjanpand
10 Replies

10. Shell Programming and Scripting

Trying to get list of logged on users sorted

I'm trying to execute a single shell command that will give me a sorted list of all the users currently logged into the system, displaying the users name as it appears in /etc/passwd. I've tried awk -F: '{print $1}' /etc/passwd | xargs finger -s | cut -c11-28 | uniq This list whoever does... (7 Replies)
Discussion started by: kungfuice
7 Replies
Login or Register to Ask a Question