script to grep latest outofmemory string from the logs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to grep latest outofmemory string from the logs
# 15  
Old 12-16-2010
Code:
$ echo $error | sed "s/.*\.\([^:]*\).*/\1/"
OutOfMemoryError

If you know that you expect an OutOfMemory error, why do you need to extract it?

Last edited by Scott; 12-16-2010 at 09:16 AM..
# 16  
Old 12-16-2010
Hello scottn,

Actually I was having requirement to grep for latest outofmemory message from the logs and send an lert if it is there. The code which i was using it tail 10 lines of logs and grep outofmemory message and sends alert. But this code is not perfect as if logs are not updated then it will grep for old message and still sneds an alert. Is it possible for you to help me design script which will grep for outofmmeory message from logs and send alert only when it is latest.

Thanks in advance.

---------- Post updated at 09:08 AM ---------- Previous update was at 08:23 AM ----------

Hello scottn,

My requirement is to grep for latest outofmemory error messages from the logs and should send an alert if there is any outofmemory error in the logs.
# 17  
Old 12-16-2010
I think I know what your requirement is. Bumping your post is more likely to get you a PM than a solution!

If you want to send "alerts" for new occurrences of the error, then you need a point of reference, most likely using the timestamps in the input file.

Not very elegant, and I'm sure someone (please!) will improve on it:

Code:
#Some variables
D=/tmp             # Change this if you want
F=$D/.latest       # Timestamp of last-found error
L=$F.log           # Text to mail at the end, if any
INFILE=file1       # The input file where to find OutOfMemory errors

rm -f $L

N=$(date '+%y%m%d%H5M%S')

[ ! -f $F ] && echo $N > $F || N=$(cat $F)

awk -F"[: /\[]" '/OutOfMemory/ && $4*1$2$3$5$6$7 > N {
 N = $4$2$3$5$6$7; print > L
}
END {
  print N > F
}
' N=$N F=$F L=$L $INFILE

[ -f $L ] && uuencode $L $L.txt | mailx -s "OutOfMemory alert" some.one@some.where

# 18  
Old 12-17-2010
Hello scottn,

Thanks for the script. Is it possible to know if script is grepping for latest outofmemory error messages and not sending old messages. Also if there is not latest outofmemory message then it should write in some file that there is no latest outofmemory message in the logs.I really appreciate your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

2. UNIX for Beginners Questions & Answers

Grep a pattern & Email from latest logs

MyLOG: 2017/11/12 17:01:54.600 : Error: LPID: 3104680848 WRONG CRITERIA FOUND. tRealBuilder::Generate Output Required: If Ke word "WRONG CRITERIA FOUND" in latest log ( logs are regularly generating - real time) mail to us once mailed wait for 2 hours for second mail. mail subject... (3 Replies)
Discussion started by: vivekn
3 Replies

3. Shell Programming and Scripting

Search string or words in logs without using Grep

I'm in need of some kind of script that will search for a string in each logfile in a directory but we don't want to use GREP. GREP seems to use up to much of our memory causing the server to use up a lot of swap space. Our log files are bigger than 500M on a daily basis. We lately started... (8 Replies)
Discussion started by: senormarquez
8 Replies

4. Shell Programming and Scripting

Script to grep logs for Errors

Hi Guys, I want to write a script which can grep the logs (server.log) from a file for Error String and output to a other file. Problems: How to know about the errors only between the current restart and not in previous as server.log has earlier restarts also? thanks for the help! Much... (5 Replies)
Discussion started by: ankur328
5 Replies

5. Shell Programming and Scripting

To find latest set of logs among new and old

Hi All I am writing a script which will select the latest logs (which are generated every night via a script) among old one and new. Script generates set of 3 logs each time it runs. Example : log-WedJun082011_bkt1.log log-WedJun082011_bkt2.log log-WedJun082011_bkt3.log I have... (1 Reply)
Discussion started by: ratneshnagori
1 Replies

6. Shell Programming and Scripting

shell script to grep 500 error messages from access logs

Hello Team, I need help to improve my script which is used to grep 500 error messages in the logs. I am using following logic in the script to grep 500 error messages in the logs. var1=`awk '$9 == "500"' access_log | tail -1` The above logic is not useful if logs are not getting... (1 Reply)
Discussion started by: coolguyamy
1 Replies

7. Shell Programming and Scripting

script to grep outofmemory message in logs

I have prepare script to grep for outofmemory messages in the logs. I need help in modifying script. I have implemented small logic. The outofmemory messages form six logs will store in variables. var1=`grep -i outofmemory $tomcat1logs | sed -n '$p'| sed -n -e "s/.*\(outofmemory\).*/\1/p"`... (6 Replies)
Discussion started by: coolguyamy
6 Replies

8. Shell Programming and Scripting

Grep string from logs of last 1 hour on files of 2 different servers and calculate count

Hi, I am trying to grep a particular string from the files of 2 different servers without copying and calculate the total count of its occurence on both files. File structure is same on both servers and for reference as follows: 27-Aug-2010... (4 Replies)
Discussion started by: poweroflinux
4 Replies

9. UNIX for Dummies Questions & Answers

grep -c script counting string twice instead of once?

I tried this script to get a count of the occurrence of a string in files. I have multiple files in one directory I will use this on. All the filenames begin "invALL.06" The script works, except it counts twice for every one instance of 'Invoice Total'. If there are 5 occurences of 'Invoice... (2 Replies)
Discussion started by: scarletsupra
2 Replies

10. Shell Programming and Scripting

Grep yesterday logs from weblogic logs

Hi, I am trying to write a script which would go search and get the info from the logs based on yesterday timestamp and write yesterday logs in new file. The log file format is as follows: """"""""""""""""""""""""""... (3 Replies)
Discussion started by: harish.parker
3 Replies
Login or Register to Ask a Question