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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |