in reply to help with scp error codes

On my system, scp return an error code on error. ("DIAGNOSTICS: scp exits with 0 on success or >0 if an error occurred.") system returns and sets $? to a value that contains the exit code of the process it launched.

my $filetoget = "$f.\@FILEDOMAIN$i.$year-$mon-$mday"; my @cmd = ( '/usr/bin/scp', "$a:$LOGFILEDIR/$filetoget", "$filetoget.$a", ); my $rv = system(@cmd); if ($rv == -1) { print("Unable to execute scp: $!\n"); } elsif ($rv & 127) { printf("scp died with signal %d\n", ($rv & 127)); } elseif {$rv >> 8) { printf("scp exited with error %d\n", ($rv >> 8)); } else { print("scp was successful\n"); }

As for the email part, MIME::Lite should do the trick.

Update: Oops, was missing scp's 2nd arg.

Replies are listed 'Best First'.
Re^2: help with scp error codes
by tachyon-II (Chaplain) on Mar 16, 2008 at 09:21 UTC

    MIME::Lite is a fine (and more reliable) option, but seeing we are just shelling out to scp why not just invoke sendmail directly by opening a pipe and sending it the required data:

    my $sendmail = "/usr/sbin/sendmail -t"; open MAIL, "|$sendmail" or die "Cannot open $sendmail: $!"; print MAIL <<EMAIL; Reply-to: $reply_to Subject: $subject To: $send_to Content-type: text/plain $content . EMAIL close MAIL;