Scan of log file in Linux for entries in last 15 minutes for matching a pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scan of log file in Linux for entries in last 15 minutes for matching a pattern
# 1  
Old 03-05-2014
Code Scan of log file in Linux for entries in last 15 minutes for matching a pattern

Is there any way I can do scan of log file in Linux, where the log file entries for last 15 minutes can be searched for a particular pattern.

The log file entries are in below format.

2014-01-27T23:08:53.924-0500 LDAP authentication error
2014-01-27T23:08:53.934-0500 LDAP authentication error

My intention is to send an email alert if there is any entry in this file for the pattern in last 15 minutes.

Thanks,
Anand
# 2  
Old 03-05-2014
Logic would be...

1. Get current time

2. subtract 15 minutes from time

3. Convert it to the same format as the log entry: YYYY-01-27 and HH:MM.SS.ddd (you only need the HH:MM)

Code:
date --date-string="- 15 minutes"....depends on o/s...this works on bash

or

date  +%Y-%M-%dT%H:%M --date="-15 minutes"
2014-21-05T16:21

4. grep or awk the log file (using regular expression if need be)...

something to get you started

Last edited by blackrageous; 03-05-2014 at 06:40 PM..
# 3  
Old 03-05-2014
Hi,

The pattern is as below.

LDAP authentication error: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903AA

Thanks,
Anand
# 4  
Old 03-05-2014
See this link for doing it in awk...

Time Functions - The GNU Awk User's Guide
# 5  
Old 04-09-2014
Hi,

From your replies i figured out this, but problem is that the command will not output anything if there is no entry for the particular minute, i.e 15 minutes before.
Code:
sed -n "/^$(date --date='15 minutes ago' '+%Y-%m-%dT%H:%M')/,\$p" $ERROR_LOG

Is there any way to fix this?

Thanks & regardsSmilie,
Anand
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check file creation Time minutes and if file older then 5 minutes execute some stuff

Hello all, Info: System RedHat 7.5 I need to create a script that based on the creation time, if the file is older then 5 minutes then execute some stuff, if not exit. I thought to get the creation time and minutes like this. CreationTime=$(stat -c %y /tmp/test.log | awk -F" " '{ print... (3 Replies)
Discussion started by: charli1
3 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. Shell Programming and Scripting

Big pattern file matching within another pattern file in awk or shell

Hi I need to do a patten match between files . I am new to shell scripting and have come up with this so far. It take 50 seconds to process files of 2mb size . I need to tune this code as file size will be around 50mb and need to save time. Main issue is that I need to search the pattern from... (2 Replies)
Discussion started by: nitin_daharwal
2 Replies

4. Shell Programming and Scripting

Grep log file to get line above matching pattern

Hi, I have a log file that looks like this "delete" : { "_type" : "cl", "_id" : "1000600000000562636", "_version" : 1, "status" : 200, "found" : false } }, { "delete" : { "_type" : "cl", "_id" : "1000600000000562643", ... (4 Replies)
Discussion started by: wahi80
4 Replies

5. 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

6. 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

7. Shell Programming and Scripting

Scan log file for errors

Hi everyone. I am still new to UNIX, and am having trouble figuring out how to create a script to scan a log file to look for errors based on a string. We run AIX 5.3, and would like the ability to report all the instances of WebSphere Broker Execution groups crashing. This script would... (8 Replies)
Discussion started by: jimbojames
8 Replies

8. Shell Programming and Scripting

Log File Scan

I need to read the last line of a log file and save it, sleep for X minutes and read the last line again. If the line is the same, exit 1, otherwise sleep for X minutes until the last line contains 'Status: Process completed'. Can anyone offer advice here? Thanks. (2 Replies)
Discussion started by: mode09
2 Replies

9. Shell Programming and Scripting

Shell Script to continuously scan a log file

Hello members, I have some doubts on how to write a script that can reports success / failure of a batch job ? 1. Run a batch job: 2. Wait and search for a particular string in the Log file: tail -f log01*.txt | egrep -v "^SUCCESSFUL" echo "continue with the other tasks" ... (1 Reply)
Discussion started by: novice82
1 Replies

10. Shell Programming and Scripting

Scan a log file

hi guys, i am very new to scripting & lookin for a shell script/perl script which would scan another file with the keyword "no change" & take a count of the same. Let me know if any further details are required. (3 Replies)
Discussion started by: nhanda
3 Replies
Login or Register to Ask a Question