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:
- Connect to the remote box via PuTTY, as in your example.
- While on the remote box, create a script to echo "hi". Name it
hello.sh
.
- Right-click the PuTTY window caption and select 'Change Settings...".
- Type the name
my-saved-session
and click Save then Cancel.
- Exit the session. Open the PuTTY Configuration panel again.
- Select your saved
my-saved-session
session and click Load.
- On the left of the 'Category' tree view, click 'SSH'.
- In the 'Remote command' box type
/hello.sh -o
.
- 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