I am looking to script something in batch which will need to run remote ssh commands on Linux. I would want the output returned so I can either display it on the screen or log it.
I tried putty.exe -ssh user@host -pw password -m command_run
but it doesn't return anything on my screen.
Anyone done this before?
You can also use
Bash on Ubuntu on Windows
directly. E.g.,Per Martin Prikryl's comment below:
As an alternative option you could install OpenSSH http://www.mls-software.com/opensshd.html and then simply
ssh user@host -pw password -m command_run
Edit: After a response from user2687375 when installing, select client only. Once this is done you should be able to initiate SSH from command.
Then you can create an ssh batch script such as
The
-m
switch of PuTTY takes a path to a script file as an argument, not a command.Reference: https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter3.html#using-cmdline-m
So you have to save your command (
command_run
) to a plain text file (e.g.c:\path\command.txt
) and pass that to PuTTY:Though note that you should use Plink (a command-line connection tool from PuTTY suite). It's a console application, so you can redirect its output to a file (what you cannot do with PuTTY).
A command-line syntax is identical, an output redirection added:
See Using the command-line connection tool Plink.
And with Plink, you can actually provide the command directly on its command-line:
Similar questions:
Automating running command on Linux from Windows using PuTTY
Executing command in Plink from a batch file