in reply to Checking mail command for success

What's the problem? Is $? not suitable for some reason?

Note that you're subject to attacks by passing unescaped text to the shell.

Replies are listed 'Best First'.
Re^2: Checking mail command for success
by ronix (Novice) on Apr 23, 2009 at 19:27 UTC

    Note that you're subject to attacks by passing unescaped text to the shell.

    Sorry, but could you explain this in more detail?

    thanks!

      "John Doe <john@example.org>" (minus the quotes) is a valid email address, but you'll have problems if $recipients contains that.

      And of course, there's the malicious who might find a way of getting "| rm -rf /" (minus the quotes) into $host or $recipients.

      The multiple argument form of various commands gets around that problem.

      use IPC::Open3 qw( ); open(my $mailer_fh, '|-', '/bin/mail', '-s', $hostn, $recipients) or die("Cannot execute mail command: $!\n"); open(my $msg_fh, '<', $disk_changes) or die("Cannot execute message file: $!\n"); print $mailer_fh $_ while <$msg_fh>; close($mailer_fh) or die("Error sending mail message: $!\n"); $? == 0 or die("Error sending mail message: $?\n");