Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'm struggling with trying to identify a failure in a set of piped commands run on a remote host via ssh. I use perl to build and run the command line as below
ssh $TARGET_HOST "sudo find $TARGET_DIR -name \'$TARGET_FILE\' | sudo +cpio --create --format ustar" | bzip2 -9 -c
Initially I just redirected the output to a file, which is fine if both the $TARGET_DIR and $TARGET_FILE exists. However, if one or both do not exist, then I still get a file created, but it's empty.
Things I've tried:
With $ret=system($cmd); and testing the the value of $ret:
  • Pre-fixing the cmd with set -o pipefail &&.
  • Adding set -o pipefail to the command run by ssh.
  • Adding set -o pipefail to the command run by sudo.
  • Doing the bzip2 locally.
    With @results = `$cmd`, and testing the value of $?:
  • Adding ; echo \${PIPESTATUS\@}; to the end of $cmd, within the string passed to ssh.
  • Adding ; echo \${PIPESTATUS\@}; to the end of $cmd, after the string passed to ssh.
    Using the @results approach, I only get one entry, so I suspect that the backtick method only sees one stream?

    Any ideas on how I can detect the remote pipeline failure?

    In reply to Re^3: best practices for checking system return values for piped commands? by Anonymous Monk
    in thread best practices for checking system return values for piped commands? by markjugg

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



    • Are you posting in the right place? Check out Where do I post X? to know for sure.
    • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
      <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
    • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
    • Want more info? How to link or How to display code and escape characters are good places to start.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others learning in the Monastery: (2)
    As of 2024-04-19 00:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found