0

I am using uuencode with mailx to attach a zip file. In following code, the if block works perfectly and I get Deletions.zip as an attachment in the email. But, whenever the else block is executed I don't get the attachment but the binary code in the email body instead.

Code (Perl code invoking linux commands):

open(EF,'>', "/test/emailbody.txt") or die $!;
if ($#dzones != -1) {
        unshift @dzones, "Following files have 20% or more deletions --\n\n";
        unshift @dzones, "Start time: $localtime\n\n";
        my $localtime = scalar localtime();
        push @dzones, "End time: $localtime\n\n";
        print EF @dzones;
        `cd /test/DOUT/; zip -q9 /tmp/deletions.zip ./*.*`;
        `(cat /test/emailbody.txt;uuencode /tmp/deletions.zip Deletions.zip) | mailx -s "Device deletions" vishal\@test.com`;
} else {
        push @dzones, "No files have more than 20% deletions.\n\nPlease see attached for the deletions in different zones.\n\nThanks, Vishal\n\n";
        print EF @dzones;
        `cd /test/DOUT/; zip -q9 /tmp/deletions.zip ./*.*`;
        `(cat /test/emailbody.txt;uuencode /tmp/deletions.zip Deletions.zip) | mailx -s "Device deletions" vishal\@test.com`;
}
close(EF);

When else block is executed, all I get is:

begin 644 Deletions.zip
M4$L#!!0``@`(`.U6,D4]>N/[=0$``&@&```D`!4`9&5L7VYE7T%L8F5R=&%?
… [snip] …
+`"H+``"R'```````
`
end

What am I doing wrong?

  • I'd close EF or flush it before running that cat /test/emailbody.txt command, in case the output is being buffered. – Mark Plotnick Sep 18 '14 at 15:49
  • Yes, I thought that too but it's not resolving the problem. – Vishal Sep 18 '14 at 16:31
1

It looks like the causing problem is being caused during looping of while cat /test/emailbody.txt;

Remove the "," while printing in file. Following line of code has this problem:

push @dzones, "No files have more than 20% deletions.\n\nPlease see attached for the deletions in different zones.\n\nThanks, Vishal\n\n";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.