Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

my perl script won't send any mails

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
cc
Posts: 820
Joined: 2005-06-08 19:14

my perl script won't send any mails

#1 Post by cc »

hi

I have this perl script, but it won't send any mails:

Code: Select all

#!/usr/bin/perl -w

use strict;
use warnings;

my $PingHost = "10.10.0.12";
my $ExpectedRedirect = "10.10.0.10";
my $mailto = "admin\@mydomain.net";

my $ip = 'ip route flush cache';

open( INPING, "ping -c 4 $PingHost|" ) || die "ping open failed";
while( my $line = <INPING> ) {
  next unless( $line =~ /Redirect Host\(New nexthop: (.*)\)/ );
  next if( $1 eq $ExpectedRedirect );

   open( OUTMAIL, "| mailx -s 'CH Branch VPN Unexpected Redirect: $1' $mailto" ) || die "pipe to mail failed";
   print OUTMAIL scalar localtime();
   print OUTMAIL "\n\n";
   print OUTMAIL "Received an unexpected redirect \n";
   print OUTMAIL "\n";
   print OUTMAIL "have a nice day\n";   
}
close(INPING) || warn "bad pipe close";

exit;
knows someone what's wrong and howto solve this problem ?

User avatar
kink
Debian Developer, Site Admin
Debian Developer, Site Admin
Posts: 248
Joined: 2006-01-02 16:47
Location: Utrecht, The Netherlands
Been thanked: 1 time

#2 Post by kink »

From a cursory look my best guess is that your regular expression does not match and therefore no mail is sent. You could try to deduce where it fails by adding some debug statements.

User avatar
drl
Posts: 427
Joined: 2006-09-20 02:27
Location: Saint Paul, Minnesota, USA

#3 Post by drl »

Hi.

I checked that my mailx would send messages, then I created the stripped-down version of your script as noted below and it worked for me.

You could remove the test and see if the print will work. You could also make the print go to STDOUT if you suspect the mailx-pipe chain ... cheers, drl

Code: Select all

#!/usr/bin/perl

# @(#) p1       Demonstrate mail from perl script.

use strict;
use warnings;
use Carp;

my ($mail);
my ($program)   = "mailx";
my ($recipient) = "drl";
my ($domain)    = '@leap';

open $mail, "|-", "$program -s test $recipient$domain"
    || croak("Can't fork $program, error $!");

print $mail scalar localtime(), "\n";
print $mail "hello, world.\n";

close $mail || croak("Can't close $program: error $!");

exit(0);
["Sure, I can help you with that." -- USBank voice recognition system.
( Mn, 2.6.x, AMD-64 3000+, ASUS A8V Deluxe, 3 GB, SATA + IDE, NV34 )
Debian Wiki | Packages | Backports | Netinstall

User avatar
arnestig
Posts: 13
Joined: 2006-11-21 09:19
Location: Grästorp, Sweden

#4 Post by arnestig »

example using sendmail:

Code: Select all

#!/usr/bin/perl
open (OUT,"|/usr/sbin/sendmail -F 'input_the_sender_name' -f sender_adress\@thedomain.com -t");
print(OUT "To: send_to_adress\@thedomain.com\n");
print(OUT "Subject: "Just an example"\n");
print(OUT "\n");
print(OUT "Test example"\n");
close(OUT);

Post Reply