Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Log File parser

Reply
Thread Tools

Log File parser

 
 
George Monappallil
Guest
Posts: n/a
 
      01-14-2005
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



 
Reply With Quote
 
 
 
 
Sherm Pendley
Guest
Posts: n/a
 
      01-14-2005
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
 
Reply With Quote
 
 
 
 
George Monappallil
Guest
Posts: n/a
 
      01-14-2005
Great...will do so surely.

-G
"Sherm Pendley" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
jc8glp1hu
Guest
Posts: n/a
 
      01-14-2005
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 => '(E-Mail Removed)',
>From => '(E-Mail Removed)',

Subject => "WARN and ERROR in $logFile",
Message => $message,
);
sendmail(%mail);

 
Reply With Quote
 
Michele Dondi
Guest
Posts: n/a
 
      01-14-2005
On Thu, 13 Jan 2005 23:25:54 -0500, Sherm Pendley
<(E-Mail Removed)> 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,
 
Reply With Quote
 
Michele Dondi
Guest
Posts: n/a
 
      01-14-2005
On 13 Jan 2005 23:16:58 -0800, "jc8glp1hu" <(E-Mail Removed)>
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,
 
Reply With Quote
 
jc8glp1hu
Guest
Posts: n/a
 
      01-14-2005
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.

 
Reply With Quote
 
jc8glp1hu
Guest
Posts: n/a
 
      01-14-2005
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.

 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      01-14-2005
jc8glp1hu <(E-Mail Removed)> 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
 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      01-14-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding Windows Event Log File Parser in JAVA amit3281@gmail.com Java 18 07-25-2007 11:47 AM
Regarding Windows Event Log File Parser in JAVA amit3281@gmail.com Java 0 07-10-2007 01:30 PM
How to log independently of other webapps using log4j? Also, reading from log file from within servlet? unomystEz Java 0 11-19-2006 10:42 AM
Application log file parser Ben_ Java 5 06-29-2004 05:04 AM
Urgent Pls: Facing problem in reading Log information from Log file, created by IIS Amratash ASP .Net 0 04-13-2004 09:08 AM



Advertisments