I have to run a shell script (windows/Linux) on a remote machine.
I have SSH configured on both machine A and B. My script is on machine A which will run some of my code on a remote machine, machine B.
The local and remote computers can be either Windows or Unix based system.
Is there a way to run do this using plink/ssh?
If Machine A is a Windows box, you can use Plink (part of PuTTY) with the -m parameter, and it will execute the local script on the remote server.
If Machine A is a Unix-based system, you can use:
You shouldn't have to copy the script to the remote server to run it.
I use this one to run a shell script on a remote machine (tested on /bin/bash):
Assuming you mean you want to do this automatically from a "local" machine, without manually logging into the "remote" machine, you should look into a TCL extension known as Expect, it is designed precisely for this sort of situation. It's home page below looks kind of crappy but don't let that dissuade you; I've also provided a link to a script for logging-in/interacting via SSH.
http://expect.nist.gov/
http://bash.cyberciti.biz/security/expect-ssh-login-script/
This bash script does ssh into a target remote machine, and run some command in the remote machine, do not forget to install expect before running it (on mac
brew install expect
)I've started using Fabric for more sophisticated operations. Fabric requires Python and a couple of other dependencies, but only on the client machine. The server need only be a ssh server. I find this tool to be much more powerful than shell scripts handed off to SSH, and well worth the trouble of getting set up (particularly if you enjoy programming in Python). Fabric handles running scripts on multiple hosts (or hosts of certain roles), helps facilitate idempotent operations (such as adding a line to a config script, but not if it's already there), and allows construction of more complex logic (such as the Python language can provide).
That will prompt you for password, unless you have copied your hostA user's public key to the authorized_keys file on the home of user .ssh's directory. That will allow for passwordless authentication (if accepted as an auth method on the ssh server's configuration)