You'll need to download the content of the script in some way. You could do
ssh remote-host cat script.bash | bash
But that would have the same kind of problem as:
cat script.bash | bash
namely that stdin within the script would be the script itself (which could be an issue if commands within the script need to get some input from the user).
Then, a better alternative (but you'd need a shell with support for process substitution like ksh, zsh or bash) would be:
bash <(ssh remote-host cat script.bash)
Both approaches do download the script in that they retrieve its content, but they don't store it locally. Instead the content is fed to a pipe whose other end is read and interpreted by bash
.
You can also have the content of the remote script executed in the current bash process with:
eval "$(ssh remote-host cat script.bash)"
But that downloads the script fully (and stores it in memory) before running it.
The obvious solution would be to do:
. <(ssh remote-host cat script.bash)
But beware that some versions of bash have issues with that.
I don't know an easy way of exporting environmental variables to target, but your script might work if you replace '
with "
. With '
s the string 'cd ${LOCATION}; ./${EXEC}'
gets passed verbatim, but with
ssh username@target "cd ${LOCATION}; ./${EXEC}"
variable substitution is done locally.
Note that the values of LOCATION
and EXEC
are passed to the remote shell, so this only works if they don't contain any shell special characters.
Best Answer
This can be done by installing Cygwin and an openssh server on your Windows machine. Cygwin will come with bash, which can run your script, and openssh can be installed under Cygwin, and will allow you to login to the Windows machine remotely. Before logging in, you can transfer your script to the Windows machine using scp, and then run it directly with ssh.
openssh can be installed using the cygwin setup program. For more detailed instructions, see http://www.howtogeek.com/howto/41560/how-to-get-ssh-command-line-access-to-windows-7-using-cygwin/