Run remote command with putty

You might want to use plink (which is shipped with putty) instead of putty for this.

Quote from the documentation:

Plink is a command-line connection tool similar to UNIX `ssh'. It is mostly used for automated operations, such as making CVS access a repository on a remote server.

For your example:

plink -ssh user@host -pw password echo "hi"

Per the putty manual, there is only -m which can be used to give it a file containing one or more commands to be executed in sequence.


As @GeraldSchneider suggests, PLINK is more suitable, but if you really wanted to use PuTTY this is how you could do it:

First, you need to set a few things up as follows:

  1. Connect to the remote box via PuTTY, as in your example.
  2. While on the remote box, create a script to echo "hi". Name it hello.sh.
  3. Right-click the PuTTY window caption and select 'Change Settings...".
  4. Type the name my-saved-session and click Save then Cancel.
  5. Exit the session. Open the PuTTY Configuration panel again.
  6. Select your saved my-saved-session session and click Load.
  7. On the left of the 'Category' tree view, click 'SSH'.
  8. In the 'Remote command' box type /hello.sh -o.
  9. Click back on 'Session' and click Save.

Now you're good to run the command:

putty -ssh user@host -pw password -load my-saved-session

Tags:

Putty