Operating System - HP-UX
1829347 Members
5075 Online
109991 Solutions
New Discussion

perl script won't send any mails

 
SOLVED
Go to solution
'chris'
Super Advisor

perl script won't send any mails

hi

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


#!/usr/bin/perl -w

use strict;
use warnings;

my $PingHost = "192.168.0.11";
my $ExpectedRedirect = "192.168.0.1";
my $mailto = "admin\@mydomain.net";

my $ip = 'ip route flush cache';

open( INPING, "ping -c 4 $PingHost|" ) || die "ping open failed";
while( my $line = ) {
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 ?
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: perl script won't send any mails

Hi Chris:

First, look at '/var/adm/syslog/mail.log' for clues.

Regards!

...JRF...
siva0123
Trusted Contributor

Re: perl script won't send any mails

Chris,

As pointed out by JR check the mail log first.

Also Check if u r not tring to send mail behind a firewall.

Thanks,
Siva
'chris'
Super Advisor

Re: perl script won't send any mails

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

test mail from the Konsole using:

echo "Message" | mailx -s "just a test" admin@mydomain.net

works without any problems.
James R. Ferguson
Acclaimed Contributor

Re: perl script won't send any mails

Hi (again) Chris:

If you are running this on HP-UX your 'ping' syntax is wrong. What you show works for AIX.

If this is HP-UX, change:

# ping -c 4 $PingHost

...to:

# ping $PingHost -n 4

Regards!

...JRF...
H.Merijn Brand (procura
Honored Contributor
Solution

Re: perl script won't send any mails

Why not use perl Modules in the first place?

It is portable!

Some other remarks.
* -w and use warnings is double (though still better than none)
* the success or failure of ping is no guarantee at all about availability of a (mail)host

--8<---
#!/usr/bin/perl -w

use strict;
use warnings;

use Mail::Sendmail;

sendmail ({
To => "admin\@mydomain.net",
From => "me\@here.com",
Subject => "CH Branch VPN Unexpected Redirect: $1",
Message => join "\n",
scalar localtime (),
"\n",
"Received an unexpected redirect",
"",
"have a nice day",
}) or die $Mail::Sendmail::error;
Enjoy, Have FUN! H.Merijn