perlquestion
cbeckley
<p>
Good Morning!
</p>
<p>
I have a small issue that I told myself I was going to ignore because the script works just fine ... but here we are.
</p>
<p>
The script monitors replication between two databases by updating a string field on the source with a timestamp, waiting a bit, retrieving the value from the target, and sending an email if they're not the same.
</p>
<p>None of which matters because that stuff all works. And the part that doesn't work is purely cosmetic, but it's bugging me.
</p>
<p>
I've included a runnable stripped down sample script below, but the crux of the matter is this:
</p>
<code>
$source_heart_beat_timestamp = "20171207_113255";
$target_heart_beat_timestamp = "bar";
$output_msg = "Source Heart Beat TimeStamp: " . $source_heart_beat_timestamp . "\n";
$output_msg .= "Target Heart Beat TimeStamp: $target_heart_beat_timestamp";
</code>
<p>
When <code> $source_heart_beat_timestamp </code> contains something that looks like a timestamp, the trailing eol gets eaten, but only in the email body. It works fine with <code> say </code>.
<br>
When <code> $source_heart_beat_timestamp </code> contains "foo", the trailing eol is displayed properly both on stdout and in the email.
</p>
<p>
So, when <code> $source_heart_beat_timestamp </code> contains "20171207_113255"
<br>
stdout looks like:
</p>
<code>
local_do_mail:
Source Heart Beat TimeStamp: 20171207_113255
Target Heart Beat TimeStamp: bar
</code>
<p>
but the email body looks like:
</p>
<code>
local_do_mail:
Source Heart Beat TimeStamp: 20171207_113255 Target Heart Beat TimeStamp: bar
</code>
<p>
However, when <code> $source_heart_beat_timestamp </code> contains "foo"
<br>
both stdout and the email body look like:
</p>
<code>
local_do_mail:
Source Heart Beat TimeStamp: foo
Target Heart Beat TimeStamp: bar
</code>
<p>
Who's eating the eol?
<br>At this point I'm willing to blame the dog, but if anybody could point me toward a more likely suspect, I would greatly appreciate it.
<br>As would the dog.
</p>
<p>
Thanks,
<br>
cbeckley
</p>
<p>
Here's the whole script:
<readmore>
<code>
#!/usr/bin/perl
use strict;
use warnings;
use v5.16;
use MIME::Lite;
my $source_heart_beat_timestamp = '';
my $target_heart_beat_timestamp = '';
sub local_do_mail {
my ($msg_body) = @_;
my $msg = MIME::Lite->new(
From => 'cloudops@foo.com',
To => 'cbeckley@foo.com',
Subject => 'testing missing eol',
Data => $msg_body
);
$msg->send;
}
#
# The mail output here includes the \n after the source_heartbeat
#
$source_heart_beat_timestamp = "foo";
$target_heart_beat_timestamp = "bar";
my $output_msg = "Source Heart Beat TimeStamp: " . $source_heart_beat_timestamp . "\n";
$output_msg .= "Target Heart Beat TimeStamp: $target_heart_beat_timestamp";
say "local_do_mail:\n$output_msg";
local_do_mail("local_do_mail:\n$output_msg");
#
# The mail output here does not include the \n after the source_heartbeat
#
$source_heart_beat_timestamp = "20171207_113255";
$target_heart_beat_timestamp = "bar";
$output_msg = "Source Heart Beat TimeStamp: " . $source_heart_beat_timestamp . "\n";
$output_msg .= "Target Heart Beat TimeStamp: $target_heart_beat_timestamp";
say "local_do_mail:\n$output_msg";
local_do_mail("local_do_mail:\n$output_msg");
</code>
</readmore>
</p>
<p>
And here are the outputs on stdout and in the emails, respectively:
</p>
<p>
Stdout:
</p>
<code>
local_do_mail:
Source Heart Beat TimeStamp: foo
Target Heart Beat TimeStamp: bar
local_do_mail:
Source Heart Beat TimeStamp: 20171207_113255
Target Heart Beat TimeStamp: bar
</code>
<p>
And the bodies of the two emails:
</p>
<code>
local_do_mail:
Source Heart Beat TimeStamp: foo
Target Heart Beat TimeStamp: bar
</code>
<code>
local_do_mail:
Source Heart Beat TimeStamp: 20171207_113255 Target Heart Beat TimeStamp: bar
</code>