Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

problem with interpolation in an email delivered by mailx

by tommysmuffins (Initiate)
on Jun 02, 2015 at 16:40 UTC ( [id://1128801]=perlquestion: print w/replies, xml ) Need Help??

tommysmuffins has asked for the wisdom of the Perl Monks concerning the following question:

I have the following subroutine:

sub email_warning { my $threshhold_value = $ARGV[0]; my $current_load_avg = &run_sar(); my $email_body = "15 minute load average of $current_load_avg has +equaled or exceeded the threshhold you specified: $threshhold_value"; open (MAIL, "|mailx -s \"15 minute load average warning\" wentwort +h\@localhost"); # print $email_body; print MAIL $email_body; close MAIL; }

The email body I receive contains only the part of $email_body up to and including the $current_load_avg variable. e.g. "15 minute load average of 4.01" and nothing after that. I'm guessing it has to do with mailx, because if I print the $email_body scalar, it looks fine. I'm perplexed.

UPDATE: OK, this is resolved. Toolic was right, printing $current_load_avg as a test printed it on a line by itself.

As it happens, that troublesome newline character was the only thing making the email send successful. When I chomped it, all the generated emails had null message bodies. I had to add a "\n" to the

print MAIL $email_body;

statement.

Thanks everyone for the help.

Replies are listed 'Best First'.
Re: problem with interpolation in an email delivered by mailx
by toolic (Bishop) on Jun 02, 2015 at 16:52 UTC
    Maybe $current_load_avg has a newline character which mailx doesn't like: chomp
    chomp $current_load_avg;
      I bet you're right. Will test. Would a newline character terminate an email?
        This is pretty definitely what it is. I just tried printing $current_load_avg, and it printed on a line by itself.
Re: problem with interpolation in an email delivered by mailx
by GotToBTru (Prior) on Jun 02, 2015 at 16:56 UTC

    I think your diagnosis is correct. Check the logs for mailx, enable error reporting (-d -v) (update: but now I'm betting toolic has the answer!).

    Dum Spiro Spero
Re: problem with interpolation in an email delivered by mailx
by FreeBeerReekingMonk (Deacon) on Jun 02, 2015 at 16:58 UTC

    Can you reproduce the error outside perl? Thus, print the $email_body to a file, and then use shell to cat message.txt | mailx -s "Test" wentworth@localhost ?

    nevermind... ninja'd with the correct solution

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1128801]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-04-23 13:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found