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.
putty.exe -ssh user@host -pw password -m command_run
Anyone done this before?
The -m switch of PuTTY takes a path to a script file as an argument, not a command.
-m
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:pathcommand.txt) and pass that to PuTTY:
command_run
c:pathcommand.txt
putty.exe -ssh user@host -pw password -m c:pathcommand.txt
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:
plink.exe -ssh user@host -pw password -m c:pathcommand.txt > output.txt
See Using the command-line connection tool Plink.
And with Plink, you can actually provide the command directly on its command-line:
plink.exe -ssh user@host -pw password command > output.txt
Similar questions: Automating running command on Linux from Windows using PuTTY Executing command in Plink from a batch file
2.1m questions
2.1m answers
60 comments
57.0k users