grep for last 15 min of log


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep for last 15 min of log
# 1  
Old 03-01-2010
grep for last 15 min of log

I need help trying to grep for a error in log file for only last 15 min.

example

under /var/adm/messages i need to grep for "error 102" but only if it occured in last 15 mins?


Thanks
# 2  
Old 03-01-2010
Based on the information supplied the only way short of writing a custom program is to copy /var/adm/messages every 15 mins and check the file growth (if any) for messages containing the exact string "error 102". The file growth can be determined by recording "wc -l" but bearing in mind that negative growth signals a new log.
# 3  
Old 03-01-2010
Question Can you do a tail command?

Can you show what a tail command provides? That way someone can see the data format and help if any "tricks" with your request.
In other words, cut & paste the last 10-20 rows of the file into a follow-up message. Please remember to use code-tags around your pasted test to help with readability.
# 4  
Old 03-01-2010
This is one of those times I really wish everyone would just use epoch time, or something like it, in the logs. Then it's pretty simple.

Anyway, does it have to be in grep? Using the following as an example:

Code:
Mar  1 21:16:48 servername sshd(pam_unix)[1561]: authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=123.456.789.100

this should work, with adjustments as time passes. Obviously, it's pretty one-off... Considerable work would be needed before it would work in a script.

Code:
awk '{ month = strftime( "%b" , systime() ) ; day = strftime("%d",systime()) ; gsub("^0","",day) ; split($3,time,":" ) } ; $1 == month && $2 == day && ( time[1] == "21" || time[1] == "21" ) && ( time[2] <= 16 && time[2] > 1 ) && $0 ~ "error 102" {print}' /var/log/messages

I'm sure that there are some awk wizards here that could make no end of improvements... I'm not one, given the time constraints I have today.
# 5  
Old 03-01-2010
Quote:
Originally Posted by joeyg
Can you show what a tail command provides? That way someone can see the data format and help if any "tricks" with your request.
In other words, cut & paste the last 10-20 rows of the file into a follow-up message. Please remember to use code-tags around your pasted test to help with readability.
example

Code:
Mar  1 08:54:17 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 08:55:20 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 08:56:23 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 08:57:26 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 08:58:29 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 08:59:32 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 09:00:35 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 09:01:38 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 09:02:41 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 09:03:44 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 09:04:47 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 09:05:50 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 09:06:53 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 09:07:56 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 09:08:59 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 09:10:02 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 09:11:05 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host
Mar  1 09:12:08 houston1 Synergy 1.3.1: WARNING: synergyc.cpp,265: failed to connect to server: No route to host

so i wanna grep the error synergyc.cpp,265 only from the last 15 of the log.

Last edited by Scott; 03-01-2010 at 06:54 PM..
# 6  
Old 03-01-2010
Quote:
Originally Posted by shehzad_m
so i wanna grep the error synergyc.cpp,265 only from the last 15 of the log.
If you only grep the last 15 error logs (not last 15 mins error logs), you can use tail -15

Code:
grep synergyc.cpp /var/adm/messages |tail -15

# 7  
Old 03-01-2010
@shezad_m
What does an "error 102" look like in your file /var/adm/messages ?

Btw "no route to host" is a TCP/IP configuration issue on your server.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find min and max time taken from a log file

You have a log file as attached in sample input with various operations and time taken by each of them. Write a script to find the min and max time taken for each operation. Sample output is attached. Sample Input is given as below: operation1,83621 operation2,72321 operation3,13288... (1 Reply)
Discussion started by: Chandan_Bose
1 Replies

2. UNIX for Dummies Questions & Answers

Cron every 5 min

Hi, I am trying to run a script in cron every 5 min in SOLARIS 10 When I do5 * * * * /path to fileor*/5 * * * * /path to file Doesn't work. Please let me know what should I put in the cron entry Thanks (2 Replies)
Discussion started by: Rossdba
2 Replies

3. AIX

crontab every 5 min.

Hi running aix 6.1 oslevel 6100-07-03-1207 I need to confirm that this cron entry is set properly. I need it set for every 5 min. 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /path/to/script.sh it does not appear that it is running every 5 min but it did in the beginning. (4 Replies)
Discussion started by: vpundit
4 Replies

4. Shell Programming and Scripting

grep log lines logged in 10 min

A log files has lines (1 line per each log for a majority; a few for 2 lines per each log) May 31 14:00:11 rtprodapp1 local2:notice sudo: jdoe : TTY=pts/0 ; PWD=/home/jdoe ; USER=root ; COMMAND=/usr/bin/su - May 31 14:03:19 rtprodapp1 local2:notice sudo: jdoe : TTY=pts/0 ; PWD=/home/jdoe ;... (4 Replies)
Discussion started by: Daniel Gate
4 Replies

5. Shell Programming and Scripting

script use min resource ( grep grep)

Hi i wrote script use it as watchdog ( i mean it check another program (pooya) whenever that was killed (closed or crashed) it run another script (pooya_start.sh) to start it, this script work fine and do the job for me , i need help of an expert to tell me (exact command) how to change this... (8 Replies)
Discussion started by: pooyair
8 Replies

6. Shell Programming and Scripting

Get min from a column conditionally

hi, i have a file with folowing content: STORAGE PERCENTAGE FLAG: /storage_01 64% 0 /storage_02 17% 1 /storage_03 10% 0 /storage_04 50% 1 I need to get the value of STORAGE from those with FLAG=0 and which has the min PERCENTAGE i am able to get the STORAGE corresponding to... (8 Replies)
Discussion started by: kichu
8 Replies

7. Shell Programming and Scripting

How to get the counter value incremented after every 1 min?

I want to check the counter value for every 1 min until the particular counter value is reached and it should exit. Counter value: 15.( For Example) counter = 1 The start time is noted using Localtime. How can i do this in perl? Regards Archana (1 Reply)
Discussion started by: vanitham
1 Replies

8. Shell Programming and Scripting

Find a min,group by.

I have a data file with records: A123|Peter|20 A123|Jack |10 B222|Helen|15 B222|Jane |13 B222|Guy |30 I want for find the min for $3 group by $1. i.e A123|Jack|10 B222|Jane|13 Thanks. (4 Replies)
Discussion started by: Shivdatta
4 Replies

9. Shell Programming and Scripting

crontab in every 05,20,35,50 min

Hi , How can i set a cronjob which needs to run every 05,20,35,50 min . I tried 05,20,35,50 * * * * /exec/eerrtis/tttttk/AOOK00000/bin/Packing.sh.. but its giving error while saving the crontab file .... What is the correct way ??? Thanks and Regards (4 Replies)
Discussion started by: scorpio
4 Replies

10. UNIX for Dummies Questions & Answers

Best approach for a 10 min extract out of several log files with timestamped records

I have a task where I need to code a shell script to extract a 10 min range (10 min from now until now) extract of a log file. I taught I could simply use a command that would say something like Start=date - 10 min but I didn't find anything. Looks like the only solution would have to code a... (3 Replies)
Discussion started by: Browser_ice
3 Replies
Login or Register to Ask a Question