Hi I just posted a note on "Re^2: best practices for checking system return values for piped commands?", but figured I really needed to post a question, so apologies if this seems like a double post...
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 an empty .tar.bz2 file of a few bytes.
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? I'm using perl 5.8.5, bash 3.00.15(1) over RedHat ELAS4.5. I would not be permitted to install the Net::Ssh module.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.