There's an important difference between your first example and your second one, and I'm not sure what your intention really is (maybe because your examples are too contrived).

Did you actually try your second example in a shell script (or at the shell command-line prompt)? If so, were you aware that the part following the pipe symbol ("/bin/others") ends up being a process that executes on your local machine? The "echo something" part is being executed via ssh on host1, the output of that operation is then being fed through a pipe on your local machine, and your own local executable file "/bin/others" is being run to process the output.

If that is your intention, and if you are saying that the perl backtick expression is trying to execute the entire pipeline command on host1 (including the "/bin/others" part), I'd have to ask, how do you know it's happening that way? (A common refrain, seen all too often at PerlMonks: "it doesn't work" is not an adequate description of the problem.)

Try a real example whose results, if successful, would leave no doubt that the stuff between "ssh" and the pipe symbol is being run on the remote machine, and the stuff after the pipe is being run locally. Make sure the example works from the command line, then make sure the perl runtime environment matches your shell environment in the relevant respects (PATH, permissions, etc). E.g. for *n*x style machines:

# create a "special" symlink to your "cut" command: ln -s `which cut` ~/my_cut # now, assuming your home directory on host1 is different from your lo +cal one, # and you don't have a "my_cut" command in your home directory on host +1: o=`ssh host1 tail -1 /etc/passwd | ~/my_cut -d: -f3-5` echo $o # now with perl: perl -e '$_=`ssh host1 tail -1 /etc/passwd | $ENV{HOME}/my_cut -d: -f3 +-5`; print'
If that doesn't work as expected, show us the actual results.

In reply to Re: back tick to do ssh by graff
in thread back tick to do ssh by convenientstore

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.