Hi Mandeep,

 Thanks a lot,  your first option works i've  just add another switch -v to 
mail for it looks for recepient address without it.
Anyway, i will look at the second option too next.

with thanks,

/joseph

""íÁÎÄÉÐ óÉÎÇÈ âÈÁÂÈÁ"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
There are multiple ways to send mail from perl script. I think this code
will help.
---------------------------------------- 
open(ML,"|mail -s \"Subject of mesaages should be here\" [EMAIL PROTECTED]")
or die " Can't open mail handle: $!";
print ML $_ ;
close(ML);
----------------------------------------
Or
----------------------------------------
    open (SENDMAIL, "|/usr/sbin/sendmail") || die "ERROR: Can not run
sendmail";
    print SENDMAIL "MIME-Version: 1.0\n";
    print SENDMAIL "Content-Type: text/plain; charset=\"utf-8\"\n";
    print SENDMAIL "Content-Transfer-Encoding: 8bit\n";
    print SENDMAIL "To: [EMAIL PROTECTED]";
    print SENDMAIL "From: [EMAIL PROTECTED]";
    print SENDMAIL "Subject: Sunbject should be here\n\n";
    print SENDMAIL $_ ;
    close (SENDMAIL);
----------------------------------------
--
ó Õ×ÁÖÅÎÉÅÍ,
âÈÁÂÈÁ íÁÎÄÉÐ óÉÎÇÈ
úáï "òáíáëó éÎÔÅÒÎÅÊÛÎÌ"
+7(812)327-86-49
[EMAIL PROTECTED]
-----Original Message-----
From: joseph [mailto:[EMAIL PROTECTED]
Sent: Friday, June 02, 2006 6:15 AM
To: beginners@perl.org
Subject: Sendmail mail from script

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>





-- 
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