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 | |
by tommysmuffins (Initiate) on Jun 02, 2015 at 17:24 UTC | |
by tommysmuffins (Initiate) on Jun 02, 2015 at 17:45 UTC | |
|
Re: problem with interpolation in an email delivered by mailx
by GotToBTru (Prior) on Jun 02, 2015 at 16:56 UTC | |
|
Re: problem with interpolation in an email delivered by mailx
by FreeBeerReekingMonk (Deacon) on Jun 02, 2015 at 16:58 UTC |