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

Hi All, I am trying to print out diff results in the body of a mail message, but for some reason I am only able to get the contents of the MSG to print... Any suggestions would be greatly appreciated. Here's the script:

@rem = ' PERL for Windows NT - ccperl must be in search path @echo off ccperl %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 goto endofperl @rem '; use Net::SMTP; my $smtp; my @typeCmdOut; my $type; my @cmdOut; my $cmd; $CLEARCASE_COMMENT=$ENV{CLEARCASE_COMMENT}; $ELEM_NAME=$ENV{CLEARCASE_PN}; @typeCmdOut = "cleartool describe -fmt \"\%[type]p\" $ELEM_NAME"; chomp ( @typeCmdOut ); $type = @typeCmdOut[0]; #if ($ELEM_NAME=~m/txt/) if ( $type =~ m/text_file/ ) { # create command string # change command string \ to / globally # run the command, capturing the results in an array # $cmd = "cleartool diff -pred -serial " . $ELEM_NAME; $cmd = "cleartool diff -pred -serial $ELEM_NAME"; # $cmd =~ s/\\/\//g; @cmdOut = `$cmd`; } my @MSG = ("Trigger activation mail notification for controlled action on VOB ($ +ENV{'CLEARCASE_VOB_PN'}): User: $ENV{'CLEARCASE_USER'} Operation: $ENV{'CLEARCASE_OP_KIND'} Element: $ENV{'CLEARCASE_PN'} Version: $ENV{'CLEARCASE_ID_STR'} Comment: $ENV{'CLEARCASE_COMMENT'}\n"); $smtp = Net::SMTP->new('mail.xxx.com'); $smtp->mail('xxx'); $smtp->to('xxx'); $smtp->data(); $smtp->datasend("TO: xx\xx\n"); $smtp->datasend("Subject: Diffrences\n"); #foreach (@cmdOut) #{ # $smtp->datasend($_); #} $smtp->datasend(@MSG); $smtp->datasend($cmd); $smtp->dataend(); $smtp->quit; __END__ :endofperl

Thanks very much, uriashea

Code tags added by Arunbear

Replies are listed 'Best First'.
Re: Diff Result Mail Output
by grinder (Bishop) on Mar 26, 2007 at 19:24 UTC

    Obviously you've gone to some effort, so full marks for supplying the source. Regrettably, it's rather unreadable without <code> tags.

    It looks like you're using a backtick to grab some output, and mailing that. But you're not checking to see whether the command was successful or not.

    Taking a wild stab in the dark, I would say that the command cleartool is not in the PATH, and you're failing to check what happens when you try to call it. Try amending your script as follows:

    @cmdOut = `$cmd`; # add this: if ($?) { die "argh: bad things happened: $?"; }

    At least that way if you'll know if the backticked command managed to run correctly. Get back to us when you've done that.

    • another intruder with the mooring in the heart of the Perl

      grinder, Thanks for your response! Turns out the issue was two-fold; (1) the command was dying, because (2) I was missing a ccperl variable. Cheers, uriashea
Re: Diff Result Mail Output
by planetscape (Chancellor) on Mar 26, 2007 at 19:46 UTC
      planetscape, thanks very much!