How to capture the cause of the exception using unix shell?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to capture the cause of the exception using unix shell?
# 1  
Old 06-17-2011
How to capture the cause of the exception using unix shell?

Hi all,

Can u pls guide me in the following requirement,

Am capturing the exceptions and the cause of that exception from a log file.

i cud capture the exceptions by simple grep ie., with the following command

cat logfile | grep "Exceptions"

But i couldn't able to capture the cause of that exception. this cause of the exception line can be identified by a pattern "msg=" which occurs before that "Exceptions" occurence.

The thing is if i put `egrep "Exceptions" | "msg="` then it finds all the occurences of "msg=" which is indeed not necessary. i need only the "msg=" occurence line(along with the exceptions) which is found before the "Exceptions" pattern line.

Thanks in Advance!! Please help on this...
# 2  
Old 06-17-2011
please provide the snippet of your log file, and also point out the expected output.
# 3  
Old 06-17-2011
Thanks for ur response!

Log file will look like,

Code:
06-16 23:55:04,INFO,ids*************************sometext,msg=curl -H "cause of the exception"
06-16 23:55:05,WARN,,,,ids*************************sometext Exception: ids*************************sometext
06-16 23:55:04,INFO,,,,ids*************************sometext
06-16 23:55:04,INFO,ids*************************sometext,msg=curl -H "cause of the exception"
06-16 23:55:05,INFO,,,,ids*************************sometext
06-16 23:55:04,INFO,,,,ids*************************sometext
06-16 23:55:05,WARN,,,,ids*************************sometext Exception: ids*************************sometext
06-16 23:55:05,WARN,,,,ids*************************sometext Exception: ids*************************sometext
06-16 23:55:05,ERROR,,,,ids*************************sometext Exception: ids*************************sometext


output file should be like,

Code:
06-16 23:55:04,INFO,ids*************************sometext,msg=curl -H "cause of the exception"
06-16 23:55:04,WARN,,,,ids*************************sometext Exception: ids*************************sometext
06-16 23:55:04,INFO,ids*************************sometext,msg=curl -H "cause of the exception"
06-16 23:55:05,WARN,,,,ids*************************sometext Exception: ids*************************sometext
06-16 23:55:05,WARN,,,,ids*************************sometext Exception: ids*************************sometext
06-16 23:55:05,ERROR,,,,ids*************************sometext Exception: ids*************************sometext


Last edited by pludi; 06-17-2011 at 09:12 AM..
# 4  
Old 06-17-2011
does this help?
Code:
awk '/msg=/{m=$0} /Exception/{ if (m)print m; print $0; m=0}' yourLog.txt

This User Gave Thanks to sk1418 For This Post:
# 5  
Old 06-24-2011
Hi Thanks.. this code is working for me!! can u pls explain this code...
# 6  
Old 06-24-2011
if your grep support -A and -B then you can try this.

A - after
B - before

Code:
 
grep -B 1 "Exception" filename

Code:
 
awk '/msg=/{m=$0} /Exception/{ if (m)print m; print $0; m=0}' yourLog.txt

if the line has
Quote:
"msg="
word then
Quote:
/msg=/{m=$0}
is storing the whole line into the variable called
Quote:
m
then we are checking the line has the word
Quote:
"Exception"
and if the line has Exception and if the variable m also not empty then print the line and make the msg variable to zero.
This User Gave Thanks to itkamaraj For This Post:
# 7  
Old 07-07-2011
Hi Just a quick clarification,

if my exception tracking words may be "ERROR" or "Exception" or "exception".

Then shall i use it like,

Code:
awk '/msg=/{m=$0} /exception|ERROR|Exception/{ if (m)print m; print $0; m=0}' >> out3.xls yourLog.txt

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script to Capture a Screenshot

Hi All, Suppose I want to take a screenshot of a website say Google and save that image. How should I do it? I tried wget with this but of no help. It just makes a particular file in jpeg format but on opening the same it says corrupted. Although I can edit the jpeg as an HTML file. wget... (15 Replies)
Discussion started by: ankur328
15 Replies

2. Shell Programming and Scripting

Monitor logs for exception and if exception come then sent an email

Hi Folks, please advise , I have logs generated on unix machine at location /ops/opt/aaa/bvg.log , now sometimes there come exception in these logs also, so I want to write such a script such that it should continuously monitor these logs and whenever any exception comes that is it try to find... (3 Replies)
Discussion started by: tuntun27272727
3 Replies

3. Shell Programming and Scripting

How to Capture a Unix Terminal Session?

Hi All, I want to capture all the operations performed in the terminal. So to achieve this I used “script” command. This works as I expected. But this command captures all the standard output which is redirected to terminal. For example if i “tail” a file, even the tail output is getting... (2 Replies)
Discussion started by: kalpeer
2 Replies

4. Shell Programming and Scripting

Shell script to unmonitor the mounts in exception file

I am trying to write a shell script for monitoring the file system mount. command I am using will retrieve a output as shown below. /dev/fsv29 2% /apps/rj/pgl/bslSys I also need to add exception mounts in a file and I would like script to ignore the mount which I specify. If I add the... (6 Replies)
Discussion started by: chandu123
6 Replies

5. Shell Programming and Scripting

Capture makefile errors in shell script

Hi, I have a bash script which calls a few "make". I would like to know whether the makefile failed with any errors. How do I do that in the script? Thanks, S (2 Replies)
Discussion started by: suryaemlinux
2 Replies

6. Shell Programming and Scripting

How to capture RC from SAS Program into K-shell

I am running a SAS program within K-shell. This SAS program gives me return code of 3000. However, when I check return code in my K-shell, it displays RC=2. Can someone tell me how to capture RC from SAS to K-shell? Thanks. Pramodini (2 Replies)
Discussion started by: Pramodini Rode
2 Replies

7. Shell Programming and Scripting

Capture commands in unix SunOS

Hi, I would like to capture commands on Unix SunOS. I am aware of script utility but the problem is Script utility writes to file after a sizeable chunk of data. I need to access each command as they are typed, Is it possible in Unix..? Thx (1 Reply)
Discussion started by: raj_paps
1 Replies

8. Shell Programming and Scripting

Capture Shell Script Output To A File

Hi, I am running a shell script called dbProcess.sh which performs shutdown and startup of various Oracle instances we have.At the time of execution the script produces the following output to the command line window $./dbProcess.sh stop #### Run Details ###### Hostname : server-hop-1... (4 Replies)
Discussion started by: rajan_san
4 Replies

9. Shell Programming and Scripting

Exception-handling in Shell programs

Hi all, I am writing a set of scripts and some of these are nested within others. I want to be able to execute a single high-level script at the command-line, which in turn may invoke other scripts as required, and when a failure occurs in any of the nested scripts, I want to be able to track... (2 Replies)
Discussion started by: chaitu_inmage
2 Replies

10. Programming

Exception Signal 11 while running JAVA code in UNIX

Hi, when i compile my java code in UNIX using javac, the class file is getting created. But when i try to run the code using java - classpath command, i get the following error. ---------------------------------------- /u/up11/sample/request:>java -classpath /u/up11/sample/request... (0 Replies)
Discussion started by: satish2712
0 Replies
Login or Register to Ask a Question