Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: log parser

by alex_fatu (Novice)
on Jun 17, 2013 at 12:51 UTC ( #1039360=note: print w/ replies, xml ) Need Help??


in reply to log parser

thank you all!

now i have another problem. if the word is found, i need to send an email.

on perl.org/exemples i have found the following code:

#!/usr/bin/perl use strict; use warnings; # first, create your message use Email::MIME; my $message = Email::MIME->create( header_str => [ From => 'you@example.com', To => 'friend@example.com', Subject => 'Happy birthday!', ], attributes => { encoding => 'quoted-printable', charset => 'ISO-8859-1', }, body_str => "Happy birthday to you!\n", ); # send the message use Email::Sender::Simple qw(sendmail); sendmail($message);


and i have implemented it in my code as:

#!/usr/bin/perl use strict; use warnings; use Email::MIME; print "searching using regexp...\n"; open(my $in, "<", "DirectX.log") or die "Can't open DirectX.log: $! +"; while (<$in>) { if ($_ =~ /eroare+/) { print "found eroare\n"; my $message = Email::MIME->create( header_str => [ From => 'alexandru.fatu@hotmail.com', To => 'alexandru.fatu@hotmail.com', Subject => 'Error!', ], attributes => { encoding => 'quoted-printable', charset => 'ISO-8859-1', }, body_str => "Eroare gasita: $_", ); # send the message use Email::Sender::Simple qw(sendmail); sendmail($message); } } close $in or die "$in: $!";


After downloading Email::MIME and all dependencies (email::address, email::sample and many more..) i get an error:
unable to establish SMTP connection

Trace begun at C:\strawberry\perl\site\lib\Email\Sender\Transport\SMTP +.pm line 9 6 Email::Sender::Transport::SMTP::_throw('Email::Sender::Transport::SMTP +=HASH(0x1e 3e90c)', 'unable to establish SMTP connection') called at C:\strawberr +y\perl\sit e\lib\Email\Sender\Transport\SMTP.pm line 63 Email::Sender::Transport::SMTP::_smtp_client('Email::Sender::Transport +::SMTP=HAS H(0x1e3e90c)') called at C:\strawberry\perl\site\lib\Email\Sender\Tran +sport\SMTP .pm line 105 Email::Sender::Transport::SMTP::send_email('Email::Sender::Transport:: +SMTP=HASH( 0x1e3e90c)', 'Email::Abstract=ARRAY(0x1d4132c)', 'HASH(0x1ca4bec)') ca +lled at C: \strawberry\perl\site\lib\Email\Sender\Role\CommonSending.pm line 27 Email::Sender::Role::CommonSending::__ANON__ at C:\strawberry\perl\ven +dor\lib\Tr y\Tiny.pm line 76 eval {...} at C:\strawberry\perl\vendor\lib\Try\Tiny.pm line 67 Try::Tiny::try('CODE(0x1e471a4)', 'Try::Tiny::Catch=REF(0x1e31c14)') c +alled at C :\strawberry\perl\site\lib\Email\Sender\Role\CommonSending.pm line 40 Email::Sender::Role::CommonSending::send('Email::Sender::Transport::SM +TP=HASH(0x 1e3e90c)', 'Email::Abstract=ARRAY(0x1d4132c)', 'HASH(0x1e4503c)') call +ed at C:\s trawberry\perl\site\lib\Email\Sender\Simple.pm line 115 Email::Sender::Simple::send_email('Email::Sender::Simple', 'Email::Abs +tract=ARRA Y(0x1d4132c)', 'HASH(0x1d3d77c)') called at C:\strawberry\perl\site\li +b\Email\Se nder\Role\CommonSending.pm line 27 Email::Sender::Role::CommonSending::__ANON__ at C:\strawberry\perl\ven +dor\lib\Tr y\Tiny.pm line 76 eval {...} at C:\strawberry\perl\vendor\lib\Try\Tiny.pm line 67 Try::Tiny::try('CODE(0x1be23ec)', 'Try::Tiny::Catch=REF(0x1d2fb8c)') c +alled at C :\strawberry\perl\site\lib\Email\Sender\Role\CommonSending.pm line 40 Email::Sender::Role::CommonSending::send('Email::Sender::Simple', 'Ema +il::MIME=H ASH(0x1d4127c)') called at C:\strawberry\perl\vendor\lib\Sub\Exporter\ +Util.pm li ne 18 Sub::Exporter::Util::__ANON__('Email::MIME=HASH(0x1d4127c)') called at + bebe1.pl line 35


Please, tell me where do i need to put my email, my password etc..setting for sending an email.

BR,
Alex


Comment on Re: log parser
Select or Download Code
Re^2: log parser
by ultibuzz (Monk) on Jun 17, 2013 at 15:09 UTC

    check Net::SMTP::OneLiner Module
    and define your not changing variables like email, sender, host, etc. outside the while loop so you do not define them over and over.

Re^2: log parser
by FloydATC (Hermit) on Jun 17, 2013 at 15:50 UTC
    After downloading Email::MIME and all dependencies (email::address, email::sample and many more..) i get an error: unable to establish SMTP connection

    The example code you found assumes that the local host running your script has an MTA (mail transport agent) such as sendmail installed locally.

    The documentation for Email::Sender shows how to use Email::Sender::Transport for communicating with a remote SMTP server.

    -- FloydATC

    Time flies when you don't know what you're doing

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039360]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-07-14 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls