I had a similar situation once where I had to generate scripts in real-time on a local machine and then run them on a remote machine (we had a cluster glued together with ssh and the local machine was the master node). The way I handled it was to stuff the entire generated script into a here document. Our bash script looked something like this:

ssh -T nodeN <<"EOF" ... script here ... EOF

The quotes around the EOF are essential. They prevent variable names and backticks from being resolved locally. Thus they get resolved only when the script is run on the remote machine. The -T option disables pseudo-tty allocation. For reasons I don't quite remember we needed to do that to get this to work.

This approach also has the advantage that ssh will return with the exit code of the last command in the here document so you know what happened when you ran the script remotely.

As for Perl - we used it to generate the remote script and the bash command. however, the command itself was run directly via bash - but that was particular to our situation and my being neurotic about being able to inspect any generated code before I run it.

Best, beth


In reply to Re: Quoting Solutions for Nested SSH Commands? by ELISHEVA
in thread Quoting Solutions for Nested SSH Commands? by cmv

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.