LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-10-2006, 10:02 AM   #1
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Rep: Reputation: 51
my perl script won't send any mails


hi

I have this perl script, but it won't send any mails:
Code:
#!/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 ?
 
Old 11-10-2006, 10:39 AM   #2
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
maybe you need to close the OUTMAIL pipe. Or perhaps you could use Net::SMTP to send emails

Just my two cents
Cheers!
 
Old 11-10-2006, 11:33 AM   #3
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by demon_vox
maybe you need to close the OUTMAIL pipe. Or perhaps you could use Net::SMTP to send emails

Just my two cents
Cheers!
I tried to close OUTMAIL pipe using:
Code:
#!/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 OUTMAIL ;       
}
close(INPING) || warn "bad pipe close";

exit;
but still doesn't work.
 
Old 11-10-2006, 11:43 AM   #4
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
Perhaps you dont have sendmail configured properly. Have you tried using mail from the command line to see if it is working properly?
 
Old 11-10-2006, 11:55 AM   #5
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by demon_vox
Perhaps you dont have sendmail configured properly. Have you tried using mail from the command line to see if it is working properly?
yep,

test mail from the command line :
Code:
echo "Message" | mailx -s "test mail" admin@mydomain.net
works without any problems !


and at '/var/adm/syslog/mail.log' don't have any entries at this time when I start the perl script.

Last edited by cccc; 11-10-2006 at 11:57 AM.
 
Old 11-10-2006, 12:35 PM   #6
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
My guess is that mailx is working right on the perl script, but it nevers reaches that part of the code. Probably one of the ifs above make the next command execute.
I just checked the ping command and the lines never have a "Redirect Host" string on them. Which would probably make the next command execute.
Maybe you should see if those conditions are the ones you are going for. Perhaps your script is working right

Cheers!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't send mails out to the internet gubak Linux - Networking 15 08-24-2004 06:54 AM
send mails with attachment ProXXXy Linux - Networking 2 08-18-2004 03:33 AM
HELP!!! Cannot send mails in SLACKWARE 9.1 vinay_s_s Linux - Software 5 03-24-2004 08:48 AM
howto send a mail with attachment via perl script ? cccc Programming 24 03-05-2004 07:49 PM
I'm looking for a simply perl script to send mail, when ping down cccc Programming 2 01-12-2004 04:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration