Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Plz help me to create a perl script to catch errors and exceptions

by technology1980
on Aug 22, 2007 at 14:47 UTC ( #634367=perlquestion: print w/replies, xml ) Need Help??
technology1980 has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I am new to Perl Scripting and also to this group ! Can anyone help me out in creating a perl script that has to catch errors and exceptions from a log file in an UNIX box and to store those errors/exceptions into a separate file ! Thanks in adv.
  • Comment on Plz help me to create a perl script to catch errors and exceptions

Replies are listed 'Best First'.
Re: Plz help me to create a perl script to catch errors and exceptions
by Joost (Canon) on Aug 22, 2007 at 15:05 UTC
Re: Plz help me to create a perl script to catch errors and exceptions
by rvosa (Curate) on Aug 22, 2007 at 15:16 UTC
    What do you mean by "catch errors and exceptions"? That sort of phrase is typically interpreted to mean something like:
    eval { &something_that_throws_exceptions }; if ( $@ ) { &exception_handler }
    or even:
    use Exception::Class::TCF; try { &something_that_throws_exceptions } catch 'Default' => \&exception_handler;
    However, because you're also talking about log files, it sounds like you mean something else. Like how to parse a file? Regular expressions? Writing to files? It's impossible to tell. Maybe you have an example of some lines in the log, and some code you've written so far to show your intentions.
      Thanks for ur reply ! To be specific about the questions: I am tailing the log file to find out whether there are errors/exceptions occurred and right now, I am doing it manually ! I want to write a Perl script so that I would catch those errors/exceptions which are occurring in the log file : (for ex: stdouterr.log). I have given the sample errors/exceptions occurred in that log file below: <Aug 7, 2007 9:56:33 AM EDT> <Notice> <Stdout> <000000> <2007-08-07 09:56:33,486 ( DEBUG - SB Time taken: 1075> com.exception.UserPreferenceException: Unable to get preference <Aug 7, 2007 9:56:33 AM EDT> <Info> <EJB> <BEA-010051> <EJB Exception occurred during invocation from home: com.portal.inforeporting.ddabalanceservice.ejb.DDABalanceServiceFacadeEJB_dmmgvi_HomeImpl@176638e threw exception: com.ucv.core.exception.SystemException: DDABalance Business Service unavailable ErrorCode: Some code UniqueExceptionId: 1a723cd1-1ccd-44a2-8da6-417992ec003d com.core.exception.SystemException: DDABalance Business Service unavailable ErrorCode: Some code These are the sample errors/exceptions which are occurred while tailing the log file manually. Can you please help me out in writing a perl script so that these kind of errors/exceptions will be caught automatically instead of doing it manually ? Thanks.
        Could you please put the example log lines inside <code></code> tags so we can see where the line breaks are? Also, could you please explain what you mean by "catch errors/exceptions"? As I tried to explain earlier, that phrase (to "catch" an exception) means something specific that has nothing to do with log file parsing. Do you want to parse the file, match against some pattern, and then...? Write just the matching lines in another file? Play a little "ping" sound? Send an email? Note: I won't write any of these for you, but I'm willing to help you on your way.

        Update: notice how your posts are being downvoted? This is because you're being very unclear, not because you're new to perl or something like that. Be clear about what you're trying to achieve.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://634367]
Approved by marto
NodeReaper wonders through a maze of twisty little sayings, all alive

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2018-07-20 20:45 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (441 votes). Check out past polls.