juanb007 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: pattern matching and sending mail!
by thezip (Vicar) on Oct 22, 2007 at 16:55 UTC

    Juan,

    It is difficult to read your code when it is not formatted for this website. Could you please wrap your code in code tags, like: <code></code>?

    I have made an attempt to reconstruct your code from what you have provided. I think your code looks like this, but please verify:

    Updated:
    • Removed line numbering
    • Closed INFO filehandle
    • correctly closed $mailer object
    #!/usr/local/bin/perl # Program to check /var/log/messeges for alerts contining the word IDS + and send mails # in case the word is found- including the line use strict; use warnings; use Mail::Mailer; open (INFO, "/var/log/messages"); # Open the file while { @message = <INFO> / IDS/g # Read it into an array @message = $& $mailer = Mail::Mailer->new("smtp", "10.83.27.71"); $mailer->open( 'From' => 'Syslog <syslog@hpda.com.ar>', 'To' => 'gabriela pinado <gabriela.pinado@hpda.com.ar>', 'Subject' => 'PiX Detected Attack ' ); print $mailer <<@message; close($mailer) or die "can't close mailer: $!";

    Here is my revised version:

    #!/usr/local/bin/perl use strict; use warnings; use Mail::Mailer; my $mailer = Mail::Mailer->new("smtp", "10.83.27.71"); open (INFO, "/var/log/messages"); while (my $message = <INFO>) { next unless $message =~ / IDS/; $mailer->open( 'From' => 'Syslog <syslog@hpda.com.ar>', 'To' => 'gabriela pinado <gabriela.pinado@hpda.com.ar>', 'Subject' => 'PiX Detected Attack ' ); print $mailer $message; $mailer->close() or die "can't close mailer: $!"; } close INFO;

    From what I can tell, I think this should have the desired result you are looking for.


    Where do you want *them* to go today?
Re: pattern matching and sending mail!
by apl (Monsignor) on Oct 22, 2007 at 18:12 UTC
    Amplifying on the opening comment by thezip, please consider using Preview before posting a question. If you have a hard time reading your question, odds are we will too.