List,

Good day!

I'm trying to  rewrite a bash script into perl as to aid my learning 
experience.Supposedly this script would do these things;


1. Open the logfiles.
2. Check the last portion of files.
3. Check the log for an ERROR string.
4. If error is present mail.(I'm stuck here i dunno how to do it.)

I already peeking at this 
http://perldoc.perl.org/perlfaq9.html#How-do-I-send-mail%3F but i can figure 
out how to do it without the <<EOF portion i'd like instead that value of 
$_ will be the body portion of mail.

Below is my code, kindly bear for any ineffecient code feedback and 
correction are very much appreciated.



#!/bin/perl

use strict;
use warnings;
$/ = "\n";
open(FILE,"/home/teragram/status_log.txt") or die "can't open file $!\n";
my @line;

while (<FILE>)  {
    push @line, $_;
    shift @line if @line > 17;
}

my @mail2log = grep {/^ERROR/ig} @line; #get the line with that starts with 
"ERROR"


 foreach (@mail2log) {
    if ($_ =~ /^ERROR/ig) #since this could always be true i'd like to mail 
the value of $_ via Sendmail but how?
       {

        open(SENDMAIL "|/usr/sbin/sendmail -oi -t -odq")

                       or die "Can't fork for sendmail: $!\n";
         }
}


close FILE;



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to