[EMAIL PROTECTED] wrote:
I need a script which will read and send mail each time a message
with the word IDS is generated under /var/log/messages.
this is the script, which I know have lots of errors:
#!/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;
Good start. :)
use Mail::Mailer;
open (INFO, "/var/log/messages"); # Open the file
You should make it a habit to check the return value when using open().
open (INFO, "/var/log/messages") or die "Couldn't open file: $!";
while
{ $message = <INFO> / IDS/g # Read it into an array
$message = $&
$mailer = Mail::Mailer->new("smtp", "10.83.27.71");
I would guess that you want something like this:
while ( my $message = <INFO> ) {
next unless $message =~ /\bIDS\b/;
my $mailer = Mail::Mailer->new("smtp", "10.83.27.71");
You should be able to take it from here.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/