Besides being more secure, the other advantage of jeffa's solution is that it gives you standard output, standard error, and command exit status neatly packaged up. That way you can check exit status and/or standard error to see why it failed. In your example you can do something similar by redirecting standard error to a file and checking if anything ends up there, something like this:

use strict; use POSIX qw(tmpnam); my $dir = '/foo/bar'; my $server = 'fred'; my $error_file = tmpnam(); my $remotecmd = `rsh $server mkdir -p $dir 2>$error_file`; if ((stat($error_file))[7]) { local *ERROR; open ERROR, "<$error_file" or die "Failed to ope $error_file: $!\n +"; my @lines = <ERROR>; warn "Failed to make remote directory: ", join("\n", @lines), "\n" +; } unlink($error_file);
My experience with rsh is that it usually does not propagate back any bad exit status from the remote side. I do sometimes bypass ssh for internal connections.


In reply to Re: Creating path on remote host by steves
in thread Creating path on remote host by mnlight

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.