473,770 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble with Perl script

37 New Member
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.transacti on.RollbackExce ption.
at curam.util.tran saction.Resourc esJTA.Ô00000(Re sourcesJTA.java (Compiled Code))
at curam.util.tran saction.Transac tionInfo.commit (TransactionInf o.java(Compiled Code))
at curam.util.inte rnal.CuramSessi onBean.invoke(C uramSessionBean .java(Compiled Code))
at curam.util.inte rnal.CuramSessi onBean.invoke(C uramSessionBean .java(Inlined Compiled Code))
at curam.util.invo ke.EJSRemoteSta telessEJBMethod _51fe6ae7.invok e(EJSRemoteStat elessEJBMethod_ 51fe6ae7.java(C ompiled Code))
at sun.reflect.Gen eratedMethodAcc essor120.invoke (Unknown Source)
at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(DelegatingMe thodAccessorImp l.java(Compiled Code))
at java.lang.refle ct.Method.invok e(Method.java(C ompiled Code))
at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Compiled Code))
at java.security.A ccessController .doPrivileged1( Native Method)
at java.security.A ccessController .doPrivileged(A ccessController .java(Compiled Code))
at com.ibm.rmi.uti l.ProxyUtil.inv okeWithPrivileg e(ProxyUtil.jav a(Compiled Code))
at com.ibm.CORBA.i iop.ClientDeleg ate.invoke(Clie ntDelegate.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 1893
numberwhun
3,509 Recognized Expert Moderator Specialist
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
joeferns79
37 New Member
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 Recognized Expert Contributor
Is that a copy of that actual data you are using that you listed in the first post?

--Kevin
Sep 10 '08 #4
joeferns79
37 New Member
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.inte rnal.HandleExce ption.getRemote Exception(Handl eException.java (Compiled Code))
at curam.util.inte rnal.HandleExce ption.getRemote Exception(Handl eException.java (Compiled Code))
at curam.util.inte rnal.CuramSessi onBean.o00000(C uramSessionBean .java(Compiled Code))
at curam.util.inte rnal.CuramSessi onBean.invoke(C uramSessionBean .java(Compiled Code))
at curam.util.inte rnal.CuramSessi onBean.invoke(C uramSessionBean .java(Inlined Compiled Code))
at curam.util.invo ke.EJSRemoteSta telessEJBMethod _51fe6ae7.invok e(EJSRemoteStat elessEJBMethod_ 51fe6ae7.java(C ompiled Code))
at sun.reflect.Gen eratedMethodAcc essor120.invoke (Unknown Source)
at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(DelegatingMe thodAccessorImp l.java(Compiled Code))
at java.lang.refle ct.Method.invok e(Method.java(C ompiled Code))
at com.ibm.rmi.uti l.ProxyUtil$2.r un(ProxyUtil.ja va(Compiled Code))
nested exception is:
infrastructure: RUN_ID_RECORD_N OT_FOUND: Record not found.
at curam.util.data access.Database Call.o00000(Dat abaseCall.java( Compiled Code))
at curam.util.data access.Database Call.o00000(Dat abaseCall.java( Compiled Code))
at curam.util.data access.Database Call.execute(Da tabaseCall.java (Compiled Code))
at curam.fem.entit y.base.EMCheckl ist.read(EMChec klist.java(Comp iled Code))
at curam.fem.facad e.impl.EMCheckl ist.doNothing(E MChecklist.java (Compiled Code))
at sun.reflect.Gen eratedMethodAcc essor874.invoke (Unknown Source)
at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(DelegatingMe thodAccessorImp l.java(Compiled Code))
at java.lang.refle ct.Method.invok e(Method.java(C ompiled Code))
at curam.util.inte rnal.CuramSessi onBean.invoke(C uramSessionBean .java(Compiled Code))
at curam.util.inte rnal.CuramSessi onBean.invoke(C uramSessionBean .java(Inlined Compiled Code))
at curam.util.invo ke.EJSRemoteSta telessEJBMethod _51fe6ae7.invok e(EJSRemoteStat elessEJBMethod_ 51fe6ae7.java(C ompiled Code))
at sun.reflect.Gen eratedMethodAcc essor120.invoke (Unknown Source)
at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(DelegatingMe thodAccessorImp l.java(Compiled Code))
at java.lang.refle ct.Method.invok e(Method.java(C ompiled Code))
Sep 11 '08 #5
KevinADC
4,059 Recognized Expert Specialist
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
joeferns79
37 New Member
Thanks, this helped.
Sep 17 '08 #7

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

Similar topics

3
5568
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. I have a line like this: "329:47 InitGame: \.Admin\xxx\.Website\www.yyy.de\g_gametype\hq\gamename\Call of
3
6557
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 should run on a Unix box I have. Both scripts run ok, except for the part when Windows try's to call out the Unix script. I have it set up where the Unix is mapped through a drive letter and can drop stuff into the Unix box. It is going through another...
1
4690
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 of which platform I use to access the directory.) Platform 1: perl is installed in /tps/bin/perl. CPAN modules are available Perl is also installed in /usr/bin/perl Platform 1, but the modules are not accessible with this version. Platform...
9
10197
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 4 12 24 42 64 92 124 162 204 252 4 11 23 44 67 95 134 168 215 271 ..
9
20900
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 rapidshare news : http://images.rapidshare.com/software/rsapi.pl If you test it you will see that you can upload one file at time. I try to modify it in that way that script can read a text file with the names of the files i want to...
21
34438
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 obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
0
2240
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): PERL5LIB=/Users/Ric/Library/Perl/ ls XML-Parser-2.34/ XML-Parser-2.34.tar
1
2624
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 then wish to run inside a Perl script. This then becomes: Win32::Process::Create($vxsim_process_object, "C:\\Tornado\\target\\config\\simpc\\vxWorks.exe",
5
1405
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 variables. My script's output is looking a bit strange... The file is sent from a server so changing it will be difficult. Nearly all of the data are in quotes except the date and time. First line of the file are the headings, then the data:...
1
47485
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9619
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9910
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.