Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Script to search log file for last 15 mins data Post 302956542 by Don Cragun on Wednesday 30th of September 2015 08:44:56 PM
Old 09-30-2015
Quote:
Originally Posted by mutley2202
Quote:
Originally Posted by Don Cragun
Is this something you plan to run every 15 minutes (so you just want to see stuff added since your last run)?
Yes, I want it to run every 15 minutes and only add new events which have appeared in the last 15 minutes.
OK. Note that this means that if there is any delay in starting one of your 15 minute runs, some events that appeared just over 15 minutes before the late starting run may be missed, and if the next run starts on time, some events may be picked up by two runs.
Quote:
Originally Posted by mutley2202
Quote:
Originally Posted by Don Cragun
Does the log file you're examining rotate? If so, is the rotation synchronized with your script, or do you need to sometimes need to examine the end of an old log file in addition to the current log file?
Yes the log file rotates at present its approximatly once a day, when the file rotates the previous one is also gziped. The rotation isn't synced with my script as its based on volume. If we can examine the old log file in the case of rotation that would be extremely helpful.
I assume that you realize that you need to grab any events logged to your log file after the last run of your script before you gzip it; or on the next run of your script you'll need to unzip it, run your script to gather events from the end of the old log file, then rezip it, and then have your script on the start of the new log file.
Quote:
Originally Posted by mutley2202
Quote:
Originally Posted by Don Cragun
Are you looking for the 15 minutes of data before the time on the clock when you start your script, or are you looking for the 15 minutes of data ending with the timestamp on the last entry in your log file?
15 minutes of data before the time on the clock.
As mentioned before, doing it this way means that you may miss some events and may process some events twice. I strongly suggest that instead of trying to match based on timestamps you instead keep track of the line number of the last line processed in the previous run and on the next run just start processing with the next line in that log file. Doing it this way will keep you from missing events and keep you from processing some events twice.

But, if you want to do it just based on timestamps, you can use the GNU date utility's -d option with an option-argument of "now - 15 minutes" and a format of "+%s" to get the number of seconds since the Epoch for 15 minutes ago and also use date -d with an option-argument of the 2nd, 3rd, 5th, and 4th fields in your log file (month, day, year, and hr:min:sec) with the same format string and then select events where the seconds since the Epoch 15 minutes ago is less than the timestamp in the file. (Note that you also want to reject any events where the timestamp in the file is more than 900 seconds after your start time. Events meeting this criteria occurred after your script started and should be picked up by the next run of your script instead of by this run.)
Quote:
Originally Posted by mutley2202
Quote:
Originally Posted by Don Cragun
What operating system and shell are you using?
GNU/Linux, shell being used is bash.

Thanks
Hope this helps.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell-script which extract data from log file

give me a shell-script which extract data from log file on a server by giving date and time as input (for both start time and end time) and it will give the logs generated during the given time as output. (4 Replies)
Discussion started by: abhishek27
4 Replies

2. Shell Programming and Scripting

{How} Script to search a log file for a given criteria

I have to write a script to search the logfiles i.e msg.log for the following The Search Criteria is as follows 1. IP address 2. String Ex: abc.123.com 3. Timestamp ( start - end ) ex: 2008-05-04-00:30:00 - 2008-05-08-04:30:00 Can anyone help to devise a script for... (9 Replies)
Discussion started by: indiakingz
9 Replies

3. Shell Programming and Scripting

Script which will search for a file for 15 mins

Hi All, I would like to write a script which will search a file say abc.dat in /a/b/data for 15 mins only. If the script finds the file in 15 mins then it will exit will exit sucessfully and if there is no file for 15 mins it will exit and copy the last day file (abc.dat_ddmmyyhhmmss) from... (1 Reply)
Discussion started by: chandancsc
1 Replies

4. Shell Programming and Scripting

need a shell script to extract data from a log file.

If I have a log like : Mon Jul 19 05:07:34 2010; TCP; eth3; 52 bytes; from abc to def Mon Jul 19 05:07:35 2010; UDP; eth3; 46 bytes; from aaa to bbb Mon Jul 19 05:07:35 2010; TCP; eth3; 52 bytes; from def to ghi I will need an output like this : Time abc to def... (1 Reply)
Discussion started by: hitha87
1 Replies

5. Shell Programming and Scripting

Retrieve logs generated in last 10 mins from a log file using 'grep' command

HI All, I have a log file where the logs will be in the format as given below: 2011-05-25 02:32:51 INFO PROCESS STARTING 2011-05-25 02:32:52 INFO PROCESS STARTED . . . I want to retrieve only the logs which are less than 5 mins older than current time using grep... (3 Replies)
Discussion started by: rvhg16
3 Replies

6. AIX

Grep last 5 mins from log file in AIX

I want to grep only last 5 mins of a log file in bash I have a syslog which contains the following Mon Jul 11 20:47:42 Mon Jul 11 20:47:52 The following works in Unix but not in AIX . Please can you let me know as to what would be the AIX equivalent Code: for (( i = 5; i >=0;... (1 Reply)
Discussion started by: necro98
1 Replies

7. Shell Programming and Scripting

Averaging data every 30 mins using AWK

A happy Monday to you all, I have a .csv file which contains data taken every 5 seconds. I want to average these 5 second data points into 30 minute averages! date co2 25/06/2011 08:04 8.31 25/06/2011 08:04 8.32 25/06/2011 08:04 8.33... (18 Replies)
Discussion started by: gd9629
18 Replies

8. Shell Programming and Scripting

Script (ksh) to get data in every 30 mins interval for the given date

Hello, Since I m new to shell, I had a hard time to sought out this problem. I have a log file of a utility which tells that batch files are successful with timestamp. Given below is a part of the log file. 2013/03/07 00:13:50 Apache/1.3.29 (Unix) configured -- resuming normal operations... (12 Replies)
Discussion started by: rpm120
12 Replies

9. Shell Programming and Scripting

Script to search for a pattern in 30 minutes from a log file

Hello All, I have to write a script which will search for diffrent patterns like "Struck" "Out of Memory" , etc from a log file in Linux box's. Now I will be executing a cron job to find out the results by executing the script once in every 30 minutes. suppose time is 14-04-29:05:31:09 So I... (3 Replies)
Discussion started by: Shubhasis Mathr
3 Replies

10. Shell Programming and Scripting

Script to find directory is getting files in every 10 mins, if not then when last time file received

Dears, I am looking for a script which will work as a watch directory. I ha directory which keep getting files in every 10 mins and some time delay. I want to monitor if the directory getting the files in every 10 mins if not captured the last received file time and calculate the delay. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies
All times are GMT -4. The time now is 01:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy