Log File parser

Discussion in 'Perl Misc' started by George Monappallil, Jan 14, 2005.

  1. Hi guys:
    I am new to perl.Anyone has a perl script that would look for certain words
    ( ERROR, WARN ) in a log file? I would like the script to send me an
    email/page when it encounters any of the words.
    Thanks in advance,

    -George
     
    George Monappallil, Jan 14, 2005
    #1
    1. Advertising

  2. George Monappallil wrote:

    > I am new to perl.Anyone has a perl script that would look for certain
    > words ( ERROR, WARN ) in a log file? I would like the script to send me an
    > email/page when it encounters any of the words.


    What have you written so far? Post what you have, and tell us what part
    you're having trouble with, and someone here will undoubtedly be happy to
    answer your questions.

    If you need help getting started, there are a number of tutorials to be
    found at:
    <http://learn.perl.org>

    If you haven't done so already, please read the posting guidelines for this
    group - they're posted here twice a week, so a recent copy should still be
    on your news server.

    Or to put it another way: "Give a man to fish, and you feed him for a day.
    Teach him to fish, and you feed him for a lifetime." We prefer to give
    fishing lessons here.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Jan 14, 2005
    #2
    1. Advertising

  3. Great...will do so surely.

    -G
    "Sherm Pendley" <> wrote in message
    news:...
    > George Monappallil wrote:
    >
    > > I am new to perl.Anyone has a perl script that would look for certain
    > > words ( ERROR, WARN ) in a log file? I would like the script to send me

    an
    > > email/page when it encounters any of the words.

    >
    > What have you written so far? Post what you have, and tell us what part
    > you're having trouble with, and someone here will undoubtedly be happy to
    > answer your questions.
    >
    > If you need help getting started, there are a number of tutorials to be
    > found at:
    > <http://learn.perl.org>
    >
    > If you haven't done so already, please read the posting guidelines for

    this
    > group - they're posted here twice a week, so a recent copy should still be
    > on your news server.
    >
    > Or to put it another way: "Give a man to fish, and you feed him for a day.
    > Teach him to fish, and you feed him for a lifetime." We prefer to give
    > fishing lessons here.
    >
    > sherm--
    >
    > --
    > Cocoa programming in Perl: http://camelbones.sourceforge.net
    > Hire me! My resume: http://www.dot-app.org
     
    George Monappallil, Jan 14, 2005
    #3
  4. George Monappallil

    jc8glp1hu Guest

    I'm bored and I saw your post, so this is how I would do it.

    I am assuming you have the package Mail::Sendmail installed. If not,
    remove the use Mail::Sendmail; line, and then follow this as a template
    for sending yourself the message.

    http://www.perlfect.com/articles/sendmail.shtml

    Here is my script, note that it sends mail no matter what. Just check
    the var's to see if they are empty if you don't want mail daily.

    Let me know if this helps!

    Cheers

    #!/usr/bin/perl
    use strict;
    use Mail::Sendmail;

    my $logFile = "errors.log";

    my $warningLines = qx(grep WARN $logFile);
    my $errorLines = qx(grep ERROR $logFile);

    print "Warning Lines\n\n**********\n" . $warningLines . "\n\n\nError
    Lines\n\n" . $errorLines . "\n";

    my $message = "Warning Lines\n\n" . $warningLines . "\n\nError
    Lines\n\n" . $errorLines;
    my %mail = (
    To => '',
    >From => '',

    Subject => "WARN and ERROR in $logFile",
    Message => $message,
    );
    sendmail(%mail);
     
    jc8glp1hu, Jan 14, 2005
    #4
  5. On Thu, 13 Jan 2005 23:25:54 -0500, Sherm Pendley
    <> wrote:

    >Or to put it another way: "Give a man to fish, and you feed him for a day.
    >Teach him to fish, and you feed him for a lifetime." We prefer to give


    Teach him how to fish, he'll tell you that he's too hungry to loose
    his time playing with rods and lines...


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Jan 14, 2005
    #5
  6. On 13 Jan 2005 23:16:58 -0800, "jc8glp1hu" <>
    wrote:

    >my $logFile = "errors.log";
    >
    >my $warningLines = qx(grep WARN $logFile);


    Yuk!

    >my $errorLines = qx(grep ERROR $logFile);


    Yuk! x 2


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Jan 14, 2005
    #6
  7. George Monappallil

    jc8glp1hu Guest

    So, are people on google groups to criticize or help people out?

    When someone asks how to do something, they don't want to be told what
    they already know. He stated that he would like a script to check for
    those two things and mail him the results. So there it is, a script
    that does that.

    If someone asks you to do something in perl, why do you even waste your
    time posting a message that says "go to ...perl.com and you will find
    some tips.". That's completely unfair to the person asking the question
    because if they wanted to know that they would have asked something
    like "Hey, where can I get more information on learning Perl, id like
    to write this script to do .... etc".

    NOW LET ME SIDE W/ SHERM. I do believe that you should come w/ some
    code to show for what you have tried. But when I started learning Perl
    I was clueless to how to use it and it is kind of hard to get started
    unless you get a little guidance. I use it for web scripts primarily so
    these side projects are fun for me to try and figure out as I see them
    here and there.

    So instead of criticizing and posting just to have your say in things,
    why don't you try and help someone out when they have a problem.

    I wrote that script in about 5 minutes to give him something to go
    from. Instead of coming on here and complaining about someone who took
    their time to help, why don't you show how you would write it. The main
    point here is post if you are going to help, if not then don't waste
    everyone's time.

    Finally, I just don't think the purpose here is to be an almighty
    mentor and oversee what is going on by telling people to read posting
    rules and trying to be a professor pointing people in the right
    direction. This is a place to ask questions about perl to help get your
    question answered, so if you know an answer to the post then post about
    it. It just goes back to common courtesy of answering what you are
    asked. If people are asking a question they are wanting an answer, an
    instant solution, unless of course they ask not to be told how to do it
    and just be given some tips.

    Anyway, I am on here to help some people out. The script I wrote gives
    him a starting place to do what he is wanting to do. He is new to perl,
    and wanted some help, so there ya go. Take it and run with it. I hope
    what I posted has helped you some, despite rude comments from someone
    who didn't have the time to post anything constructive. They apparently
    were never new to the Perl language at all.
     
    jc8glp1hu, Jan 14, 2005
    #7
  8. George Monappallil

    jc8glp1hu Guest

    Sorry for the rant, I am not out to make anyone feel bad or offend
    anyone. I am just having some sympathy for the thread starter who asked
    a question and didn't get what he wanted because I have been told
    before to go somewhere and read up, which is what I did, but I still
    didn't "understand" what I was doing.

    Sherm is right too, head to the site he suggested to learn some more
    about it if you so desire because Perl is a really neat language.

    So, sorry to anyone I offended. I just feel strongly about helping
    people when they ask for it because we all have struggled with
    something new before.
     
    jc8glp1hu, Jan 14, 2005
    #8
  9. George Monappallil

    Anno Siegel Guest

    jc8glp1hu <> wrote in comp.lang.perl.misc:

    Please provide some context of what you are replying to.

    > So, are people on google groups to criticize or help people out?


    Both. On clpm, we help people correct their code, and we criticize code
    that is posted. The two activities are not very different, and both help
    develop the Perl language.

    And it's not "google groups" you are on, it's Usenet, which is independent
    and far older than google groups. Google runs an archive and an interface.
    That's of great merit, but it doesn't make them the same thing.

    [...]

    > If someone asks you to do something in perl, why do you even waste your


    ....but the solution you posted wasn't really in Perl. The two calls
    to grep would have been better part of some shell script. That's
    what the "yuck" was about, no more, no less.

    [rant snipped]

    Anno
     
    Anno Siegel, Jan 14, 2005
    #9
  10. Anno Siegel wrote:

    > and far older than google groups. Google runs an archive and an
    > interface. That's of great merit,


    Well... the archive is of great merit anyway. From what I've seen so far,
    the interface is basically worthless.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Jan 14, 2005
    #10
  11. jc8glp1hu wrote:

    > So, are people on google groups to criticize or help people out?


    Whoa, hold on a second. Launching a child "grep" process is unnecessary in
    this case, inefficient, and won't even work on many Windows systems. And
    your code does it *twice*.

    Michele was commenting on the code you posted, not on the fact that you
    posted code.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Jan 14, 2005
    #11
  12. George Monappallil

    jc8glp1hu Guest

    Sherm Pendly wrote:

    >Whoa, hold on a second. Launching a child "grep" process is

    unnecessary in
    this case, inefficient, and won't even work on many Windows systems.
    And
    your code does it *twice*.

    >Michele was commenting on the code you posted, not on the fact that

    you
    posted code.

    Ok, thanks that makes since. If they would have said that in the first
    place it would have been perfect! I thought about opening it within
    perl but I wasn't sure which would be more efficient.
    Thanks for clarifying!

    Cheers!
     
    jc8glp1hu, Jan 14, 2005
    #12
  13. George Monappallil

    Anno Siegel Guest

    Sherm Pendley <> wrote in comp.lang.perl.misc:
    > Anno Siegel wrote:
    >
    > > and far older than google groups. Google runs an archive and an
    > > interface. That's of great merit,

    >
    > Well... the archive is of great merit anyway. From what I've seen so far,
    > the interface is basically worthless.


    That's what I've heard. The mistake is to call a Usenet archive with (of
    course) the added ability to post "Google Groups". It's still an archive,
    with associated delay, and no replacement for an NNTP server. Never mind
    the interface...

    Anno
     
    Anno Siegel, Jan 14, 2005
    #13
  14. "jc8glp1hu" <> wrote in news:1105712217.077518.277530
    @c13g2000cwb.googlegroups.com:

    > Sorry for the rant, I am not out to make anyone feel bad or offend
    > anyone. I am just having some sympathy for the thread starter who asked
    > a question and didn't get what he wanted because


    Ahem ... The OP responded:

    "George Monappallil" <> wrote in
    news:j0IFd.32940$:

    > Great...will do so surely.
    >
    > -G


    It seems like he was fine with the answer he got.

    > I have been told before to go somewhere and read up, which is
    > what I did, but I still didn't "understand" what I was doing.


    That understanding comes from asking "smart questions" and thinking about
    the answers one gives.

    > So, sorry to anyone I offended. I just feel strongly about helping
    > people when they ask for it because we all have struggled with
    > something new before.


    It is funny how you equate helping with posting crappy code.

    It is the equivalent of giving wrong directions to a tourist instead of
    admitting you don't know.

    Ponder that for a few minutes.

    Sinan.
     
    A. Sinan Unur, Jan 14, 2005
    #14
  15. Please, when posting include some (properly trimmed down) quoted text
    from the article you're replying to, for reference...


    On 14 Jan 2005 06:09:45 -0800, "jc8glp1hu" <>
    wrote:

    >So, are people on google groups to criticize or help people out?


    Both, I'd say. Well, as long as to criticize _is_ to help "people"
    out.

    >When someone asks how to do something, they don't want to be told what
    >they already know. He stated that he would like a script to check for
    >those two things and mail him the results. So there it is, a script
    >that does that.


    I was _not_ criticizing the fact that you helped him supplying a ready
    made script. I was criticizing how _bad_ it was.

    >If someone asks you to do something in perl, why do you even waste your
    >time posting a message that says "go to ...perl.com and you will find
    >some tips.". That's completely unfair to the person asking the question


    This is an oft discussed matter here, and my opinion, as well as that
    of many others here and elsewhere is that _that_ kind of answer _can_
    be the best help that can be given, at least in certain situations.
    there's another thread going on along these lines...

    >because if they wanted to know that they would have asked something
    >like "Hey, where can I get more information on learning Perl, id like
    >to write this script to do .... etc".


    The point is that they often, as newbies, do not even know that they
    can get the information themselves or how easy it is. You know, it's
    that story of "give a man a fish..."!

    Said this, _generally_ I am one of those that supplies ready-made
    solutions even to relatively trivial questions. But I do not claim
    that it is the best thing to do and I'm not arguing with those that
    give an RTFM-kinda-answer, nay, generally if a discussion about this
    starts, then I support their POVs.

    But all this has nothing to do specifically with my post of which
    yours is a followup...

    >NOW LET ME SIDE W/ SHERM. I do believe that you should come w/ some


    Huh?!?

    >So instead of criticizing and posting just to have your say in things,
    >why don't you try and help someone out when they have a problem.
    >
    >I wrote that script in about 5 minutes to give him something to go
    >from. Instead of coming on here and complaining about someone who took


    Well, I posted in about 10 seconds, because I really hadn't more time,
    in that case.

    I _do_ apologize because taking this into account, my cmts must have
    sounded particularly aggressive. Had I had more time, as I have _now_
    I would have included a "pars construens" as well as the "pars
    denstruens", or at least explain why the latter was there.

    >their time to help, why don't you show how you would write it. The main


    Ditto as above.

    >point here is post if you are going to help, if not then don't waste
    >everyone's time.


    What is arguable is wether the kind of help you gave was really
    helping.

    In fact you will first or later discover that Perl has a bad name in
    many respects because of bad programming techniques spread around by
    script kiddies et similia.

    If you post such code in answer to a newbie's request for help, seeing
    that indeed it _does_ work, he will get used to such bad programming
    techniques...

    >Finally, I just don't think the purpose here is to be an almighty
    >mentor and oversee what is going on by telling people to read posting
    >rules and trying to be a professor pointing people in the right
    >direction. This is a place to ask questions about perl to help get your


    Still this doesn't have anything to do with my post.

    Please note that I quoted properly your article and supplied cmts on
    two specific lines of code, albeit harsh ones...

    It was up to your intelligence to understand _what_ was being
    criticized!

    >question answered, so if you know an answer to the post then post about
    >it. It just goes back to common courtesy of answering what you are


    I _do_ know an answer to _that_ post. I _may_ have given it, if had
    had more time, or I may have not, even in that case. But that's not a
    point.

    I was commenting on _your_ code, and it did make sense to do so.

    The kind of code you posted was more of a shell script written in Perl
    than a Perl script. Not to say that using any of the external
    programs exectuing commands should be prohibited in general, nay,
    indeed in certain cases this ability provides the "best" solution for
    certain tasks. But abusing it has no sense. if it must be a shell
    script, then write a shell script, else use Perl to do (more
    efficiently) what Perl can do perfectly well by itself.

    >asked. If people are asking a question they are wanting an answer, an
    >instant solution, unless of course they ask not to be told how to do it
    >and just be given some tips.


    Again, this has been discussed many times here and I'm not discussing
    it anymore now, I recommend reading some relevant threads. Your POV is
    acceptable but has not universal value. Others' opinions may vary and
    their POVs are acceptable too.

    >Anyway, I am on here to help some people out. The script I wrote gives
    >him a starting place to do what he is wanting to do. He is new to perl,
    >and wanted some help, so there ya go. Take it and run with it. I hope


    Ditto as above wrt spreading bad techniques.

    >what I posted has helped you some, despite rude comments from someone
    >who didn't have the time to post anything constructive. They apparently
    >were never new to the Perl language at all.


    Oh, no, I've been new to Perl, and I still often have the sensation of
    being new to it, when I learn something unexpected from posters by far
    more knowledgeable than me. But that's another matter, believe me...

    I've been new to Perl, but AFAICT I've never had that kind of attitude
    many newbies show to have (well, I hope so, but I cannot gurantee
    anything - I should check my first posts here)...


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Jan 15, 2005
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amratash
    Replies:
    0
    Views:
    559
    Amratash
    Apr 13, 2004
  2. Ben_
    Replies:
    5
    Views:
    13,983
    scott
    Jun 29, 2004
  3. unomystEz
    Replies:
    0
    Views:
    584
    unomystEz
    Nov 19, 2006
  4. Replies:
    18
    Views:
    1,555
    Jeff Higgins
    Jul 25, 2007
  5. Replies:
    0
    Views:
    334
Loading...

Share This Page