Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: pattern matching and sending mail!

by thezip (Vicar)
on Oct 22, 2007 at 16:55 UTC ( #646494=note: print w/replies, xml ) Need Help??

in reply to pattern matching and sending mail!


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:

  • 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", ""); $mailer->open( 'From' => 'Syslog <>', 'To' => 'gabriela pinado <>', '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", ""); open (INFO, "/var/log/messages"); while (my $message = <INFO>) { next unless $message =~ / IDS/; $mailer->open( 'From' => 'Syslog <>', 'To' => 'gabriela pinado <>', '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?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://646494]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2018-06-18 18:07 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.