Re: Sendmail mail from script (Closed)



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

""íÁÎÄÉÐ óÉÎÇÈ âÈÁÂÈÁ"" <mandeep.bhabha@xxxxxxxx> wrote in message
news:20060602051442.CF4BDA1430@xxxxxxxxxxxxxxxx
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@address")
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\@address\n";
print SENDMAIL "From: return\@address\n";
print SENDMAIL "Subject: Sunbject should be here\n\n";
print SENDMAIL $_ ;
close (SENDMAIL);
----------------------------------------
--
ó Õ×ÁÖÅÎÉÅÍ,
âÈÁÂÈÁ íÁÎÄÉÐ óÉÎÇÈ
úáï "òáíáëó éÎÔÅÒÎÅÊÛÎÌ"
+7(812)327-86-49
mandeep.bhabha@xxxxxxxx
-----Original Message-----
From: joseph [mailto:jbtacuyan@xxxxxxxxx]
Sent: Friday, June 02, 2006 6:15 AM
To: beginners@xxxxxxxx
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: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
<http://learn.perl.org/> <http://learn.perl.org/first-response>




.



Relevant Pages

  • Re: ssh-agent (was: using a remote IMAP server and smarthost)
    ... invokes ssh to run sendmail on myvm directly. ... here is the necessary wrapper script for method 2: ... Ssh-agent is part of the openssh-client package. ... Then you will get a dialog to enter the passphrase. ...
    (Debian-User)
  • Re: sendmail
    ... have applied your script but changed the ntpd service to sendmail. ... When the network manager dispatcher runs the script, ... It's been quite some time since I used dialup, ...
    (Fedora)
  • RE: Sendmail mail from script
    ... There are multiple ways to send mail from perl script. ... print SENDMAIL $_; ...
    (perl.beginners)
  • Redirecting an e-mail to a script
    ... Sendmail is now up and working great. ... redirect to a script. ... redirected to a script /opt/bb/bin/bb-mailack.sh. ... sendmail won't execute scripts. ...
    (Fedora)
  • Re: checking user via script during SMTP conversation
    ... When you are talking Perl that must be compiled this is a bit of load when you could potentially be talking about multiple times per minute or even second. ... open door to anything you can script. ... relay control by performing a snmp check on the host and checking ... They allow you to have Sendmail do SO much. ...
    (comp.mail.sendmail)