473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Trouble with Perl script

I am trying to modify a script that's supposed to extract data from a log file.

The script is as under ..
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. ####################################################################
  3. # genreport
  4. ####################################################################
  5. sub genreport {
  6.    my ($logfile, $reportfile) = @_;
  7.    my ($line, @message, @summary, $count, $match, $n);
  8.  
  9.    open(LOGFILE, "<$logfile")
  10.       or die "Can't open $logfile: $!";
  11.  
  12.    open (REPORTFILE, ">$reportfile")
  13.       or die "Can't open $reportfile: $!";
  14.  
  15.    $count = $match = 0;
  16.    while ($line = <LOGFILE>) {
  17.       chomp $line;
  18.       if (length $line) {
  19.          push @message, $line;
  20.       } else {
  21.          if ($message[0] =~ /^\[ERROR](.*)\administrator.$/) {
  22.             #foreach $n (0..$#message) {
  23.         #  if ($message[$n] =~ /^infrastructure:ID_UNHANDLED:.*/) {
  24.              $match = 1;
  25.         #   }
  26.            if (($message[$n] =~ /^nested exception is:.*/) && ($match == 1)) {
  27.            push @summary, $message[$n + 1];
  28.            }           
  29.        # }
  30.         if ($match == 1) {
  31.               foreach $line (@message) {
  32.                   printf REPORTFILE "%s\n", $line;
  33.            }
  34.                printf REPORTFILE "\n";
  35.                $count++;
  36.            $match = 0;
  37.             }
  38.          } 
  39.     else {
  40.             die "parse error: missing date";
  41.          }
  42.          @message = ();
  43.       }
  44.    }
  45.  
  46.    if ($count > 0) {
  47.       printf "There were %s un-handled server exceptions:\n\n", $count;
  48.       foreach $line (@summary) {
  49.          printf "   ***> %s\n", $line
  50.       }
  51.       printf "\n";
  52.    } else {
  53.       printf "There were no un-handled server exceptions for this reporting period.\n\n";
  54.    }
  55. }
  56.  
  57. ####################################################################
  58. # main
  59. ####################################################################
  60.  
  61. if (@ARGV != 2) {
  62.    die "usage: UAESummary.pl <logfile> <reportfile>";
  63. }
  64.  
  65. my ($logfile, $reportfile) = @ARGV;
  66.  
  67. genreport($logfile, $reportfile);
  68.  
  69. exit 0;
  70.  
  71. ############
  72.  
The log file is as under ...

[ERROR] [09 Sep 2008 13:58:59] [Trace] [WebContainer : 88] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
nested exception is:
infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
at curam.util.transaction.ResourcesJTA.Ô00000(Resourc esJTA.java(Compiled Code))
at curam.util.transaction.TransactionInfo.commit(Tran sactionInfo.java(Compiled Code))
at curam.util.internal.CuramSessionBean.invoke(CuramS essionBean.java(Compiled Code))
at curam.util.internal.CuramSessionBean.invoke(CuramS essionBean.java(Inlined Compiled Code))
at curam.util.invoke.EJSRemoteStatelessEJBMethod_51fe 6ae7.invoke(EJSRemoteStatelessEJBMethod_51fe6ae7.j ava(Compiled Code))
at sun.reflect.GeneratedMethodAccessor120.invoke(Unkn own Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
at java.security.AccessController.doPrivileged1(Nativ e Method)
at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))


#####

When I try running it though, it returns ...

C:\PerlScripts>UAESummary.bat CuramApp.log Report.log
There were no un-handled server exceptions for this reporting period.

Even though there is clearly a string that matches the regular expression in the script, unless I am missing something.

Please help.
Sep 10 '08 #1
6 1871
numberwhun
3,509 Expert Mod 2GB
Well, if I am reading this code right, then your code is doing exactly what you have told it to do. On line 16 you do an if test on "length $line". I assume this is returning true and going into that part of the if. The regex's and the $count variable are all inside of the "else" part of the if statement. The if test would have to fail for your code to work.

I think you need to re-work this code. (assuming I have read it correctly).

Also, please use code tags around your code. I have added them here for you. Simply edit your original post to see how to use them.

Regards,

Jeff
Sep 10 '08 #2
Thanks for the quick response, Jeff.

I removed that part from the code, as can be seen below...


Expand|Select|Wrap|Line Numbers
  1. use strict;
  2.  
  3.  
  4. ####################################################################
  5. # genreport
  6. ####################################################################
  7.   sub genreport {
  8.    my ($logfile, $reportfile) = @_;
  9.    my ($line, @message, @summary, $count, $match, $n);
  10.  
  11.    open(LOGFILE, "<$logfile")
  12.       or die "Can't open $logfile: $!";
  13.  
  14.    open (REPORTFILE, ">$reportfile")
  15.       or die "Can't open $reportfile: $!";
  16.  
  17.    $count = $match = 0;
  18.    while ($line = <LOGFILE>) {
  19.       chomp $line;
  20.           if ($message[0] =~ /^\[ERROR](.*)\administrator.$/) {
  21.             #foreach $n (0..$#message) {
  22.         #  if ($message[$n] =~ /^infrastructure:ID_UNHANDLED:.*/) {
  23.              $match = 1;
  24.         #   }
  25.            if (($message[$n] =~ /^nested exception is:.*/) && ($match == 1)) {
  26.           push @summary, $message[$n + 1];
  27.            }           
  28.        # }
  29.         if ($match == 1) {
  30.              foreach $line (@message) {
  31.                   printf REPORTFILE "%s\n", $line;
  32.            }
  33.                printf REPORTFILE "\n";
  34.                $count++;
  35.            $match = 0;
  36.             }
  37.          } 
  38.     #else {
  39.     #        die "parse error: missing date";
  40.     #     }
  41.          @message = ();
  42.  
  43.    }
  44.  
  45.    if ($count > 0) {
  46.       printf "There were %s un-handled server exceptions:\n\n", $count;
  47.       foreach $line (@summary) {
  48.          printf "   ***> %s\n", $line
  49.       }
  50.       printf "\n";
  51.    } else {
  52.       printf "There were no un-handled server exceptions for this reporting period.\n\n";
  53.    }
  54. }
I am still getting the same message though ...

C:\PerlScripts>UAESummary.bat CuramApp.log Report.log
There were no un-handled server exceptions for this reporting period.


I am just wondering if the reg exp is right since the code doesn't seem to be adding to the count and is printing the stmt ..

"There were no un-handled server exceptions for this reporting period.\n\n"
Sep 10 '08 #3
eWish
971 Expert 512MB
Is that a copy of that actual data you are using that you listed in the first post?

--Kevin
Sep 10 '08 #4
Yes it is. I made it work actually, but now I wanted to extract the part from the stack that says "nested exception" and was having trouble with that.

The code is as below ...

Expand|Select|Wrap|Line Numbers
  1.  while ($line = <LOGFILE>) {
  2.       chomp $line;
  3.   if (length $line) {
  4.          push @message, $line;
  5.           if ($message[0] =~ /^\[ERROR](.*)\infrastructure:ID_UNHANDLED:.*$/) {
  6.             foreach $n (0..$#message) {
  7.         #  if ($message[$n] =~ /^infrastructure:ID_UNHANDLED:.*/) {
  8.              $match = 1;
  9.         #   }
  10.            if (($message[$n] =~ /^nested exception is:(.*)/) && ($match == 1)) {
  11.           push @summary, $message[$n + 1];
  12.            }           
  13.         }
  14.         if ($match == 1) {
  15.              foreach $line (@message) {
  16.                   printf REPORTFILE "%s\n", $line;
  17.            }
  18.                printf REPORTFILE "\n";
  19.                $count++;
  20.            $match = 0;
  21.             }
  22.          } 
The report I get is as below ...

[ERROR] [09 Sep 2008 12:36:56] [Trace] [WebContainer : 78] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.

[ERROR] [09 Sep 2008 12:55:23] [Trace] [WebContainer : 83] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.

[ERROR] [09 Sep 2008 12:55:36] [Trace] [WebContainer : 80] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.

[ERROR] [09 Sep 2008 12:57:54] [Trace] [WebContainer : 77] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.


This is part of the input log(in addition to the 1st line that's captured above, I want the part below the "nested exception is:" string to be displayed too ...

[ERROR] [10 Sep 2008 10:13:17] [Trace] [WebContainer : 144] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
at curam.util.internal.HandleException.getRemoteExcep tion(HandleException.java(Compiled Code))
at curam.util.internal.HandleException.getRemoteExcep tion(HandleException.java(Compiled Code))
at curam.util.internal.CuramSessionBean.o00000(CuramS essionBean.java(Compiled Code))
at curam.util.internal.CuramSessionBean.invoke(CuramS essionBean.java(Compiled Code))
at curam.util.internal.CuramSessionBean.invoke(CuramS essionBean.java(Inlined Compiled Code))
at curam.util.invoke.EJSRemoteStatelessEJBMethod_51fe 6ae7.invoke(EJSRemoteStatelessEJBMethod_51fe6ae7.j ava(Compiled Code))
at sun.reflect.GeneratedMethodAccessor120.invoke(Unkn own Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
nested exception is:
infrastructure:RUN_ID_RECORD_NOT_FOUND: Record not found.
at curam.util.dataaccess.DatabaseCall.o00000(Database Call.java(Compiled Code))
at curam.util.dataaccess.DatabaseCall.o00000(Database Call.java(Compiled Code))
at curam.util.dataaccess.DatabaseCall.execute(Databas eCall.java(Compiled Code))
at curam.fem.entity.base.EMChecklist.read(EMChecklist .java(Compiled Code))
at curam.fem.facade.impl.EMChecklist.doNothing(EMChec klist.java(Compiled Code))
at sun.reflect.GeneratedMethodAccessor874.invoke(Unkn own Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
at curam.util.internal.CuramSessionBean.invoke(CuramS essionBean.java(Compiled Code))
at curam.util.internal.CuramSessionBean.invoke(CuramS essionBean.java(Inlined Compiled Code))
at curam.util.invoke.EJSRemoteStatelessEJBMethod_51fe 6ae7.invoke(EJSRemoteStatelessEJBMethod_51fe6ae7.j ava(Compiled Code))
at sun.reflect.GeneratedMethodAccessor120.invoke(Unkn own Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
Sep 11 '08 #5
KevinADC
4,059 Expert 2GB
I am really not clear on what you are trying to parse out of the log file, but see if this helps:

Expand|Select|Wrap|Line Numbers
  1. while ($line = <DATA>) {
  2.    if ($line =~ /^\[ERROR\](.*?)infrastructure:ID_UNHANDLED:.*$/) {
  3.       push @message, $line;
  4.       $match = 1;
  5.       next;
  6.    }
  7.    if ($match && ($line =~ /^nested exception is:/)) {
  8.        $line = <DATA>;
  9.        push @message, $line;
  10.        $match = 0;
  11.        next;
  12.    }
  13. }
  14. for (@message) {
  15.    print;
  16. }
  17. __DATA__
  18. [ERROR] [09 Sep 2008 13:58:59] [Trace] [WebContainer : 88] - infrastructure:ID_UNHANDLED: An un-handled server exception occurred. Please contact your administrator.
  19. nested exception is:
  20. infrastructure:RUN_ID_RUNTIME: A runtime exception occurred: javax.transaction.RollbackException.
  21. at curam.util.transaction.ResourcesJTA.Ô00000(Resourc esJTA.java(Compiled Code))
  22. at curam.util.transaction.TransactionInfo.commit(Tran sactionInfo.java(Compiled Code))
  23. at curam.util.internal.CuramSessionBean.invoke(CuramS essionBean.java(Compiled Code))
  24. at curam.util.internal.CuramSessionBean.invoke(CuramS essionBean.java(Inlined Compiled Code))
  25. at curam.util.invoke.EJSRemoteStatelessEJBMethod_51fe 6ae7.invoke(EJSRemoteStatelessEJBMethod_51fe6ae7.j ava(Compiled Code))
  26. at sun.reflect.GeneratedMethodAccessor120.invoke(Unkn own Source)
  27. at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java(Compiled Code))
  28. at java.lang.reflect.Method.invoke(Method.java(Compil ed Code))
  29. at com.ibm.rmi.util.ProxyUtil$2.run(ProxyUtil.java(Co mpiled Code))
  30. at java.security.AccessController.doPrivileged1(Nativ e Method)
  31. at java.security.AccessController.doPrivileged(Access Controller.java(Compiled Code))
  32. at com.ibm.rmi.util.ProxyUtil.invokeWithPrivilege(Pro xyUtil.java(Compiled Code))
  33. at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDel egate.java(Compiled Code))
  34.  
Sep 12 '08 #6
Thanks, this helped.
Sep 17 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Thorsten Walenzyk | last post by:
Hi all, I'm pretty new to PHP. So far I know regular expression only from Perl I've written a perl script which I now want to port to PHP. It works in PErl, but gives my a headache in PHP. ...
3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
1
by: Julia Bell | last post by:
I would like to run the same script on two different platforms. The directory in which the script(s) will be stored is common to the two platforms. (I see the same directory contents regardless...
9
by: Martin Foster | last post by:
Hi. I would like to be able to mimic the unix tool 'uniq' within a Perl script. I have a file with entries that look like this 4 10 21 37 58 83 111 145 184 226...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
0
by: UncleRic | last post by:
Environment: Mac OS X (10.4.10) on MacBook Pro I'm a Perl Neophyte. I've downloaded the XML::Parser module and am attempting to install it in my working directory (referenced via PERL5LIB env): ...
1
by: Tension | last post by:
Hi, I am trying to run a Tornado simulator with Perl. The command line in an ordinary Windows command window looks like this: "C:\Tornado\target\config\simpc\vxWorks.exe /r32000000" Which I...
5
by: g0uki | last post by:
Hi all, i hope you can help, I'm having some trouble getting all the data from a file, well just the date and time entries. I'll be doing operations on the data so would like to store it within...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.