I would like to copy certain logs from a remote linux system to the windows system. I'm trying to make a batch file, that will connect to the linux system using putty like:

putty.exe -ssh [email protected] -pw password 

How will I add the linux command to be run to this? Is it possible or should I look for some other software

  • 4
    This question is about the windows application putty (maybe belongs on superuser?)
    – Zelda
    Feb 24, 2014 at 10:34
  • This is not off-topic: it is about Linux. Nov 5, 2015 at 10:10
  • @reinierpost look at the answer. Everything there is on the Windows side. The OP needed to change the options on a Windows app. I don't really see how it would be on topic here. More to the point, it was closed almost a year ago and has already been answered. There doesn't seem to be much reason to open it even if it might be borderline on topic.
    – terdon
    Nov 5, 2015 at 11:54
  • It is about connecting to a Linux machine. Granted, everything he wants to know is Windows-specific. Nov 5, 2015 at 21:58

1 Answer 1

putty.exe -ssh [email protected] -pw password -m C:\local\file\containing_command

Et voilà !
simple and easy.

From putty help chapter

-m: read a remote command or script from a file
The -m option performs a similar function to the ‘Remote command’ box in the SSH panel of the PuTTY configuration box (see section 4.18.1). However, the -m option expects to be given a local file name, and it will read a command from that file.
With some servers (particularly Unix systems), you can even put multiple lines in this file and execute more than one command in sequence, or a whole shell script; but this is arguably an abuse, and cannot be expected to work on all servers. In particular, it is known not to work with certain ‘embedded’ servers, such as Cisco routers.
This option is not available in the file transfer tools PSCP and PSFTP.

According to documentation you should edit a local file and put a list of command you want to send to your server it can be a liste of command or a single command or event a remote shell script, but this might not work on every system.

Edit :

If you want to execute only one command from putty GUI you can also according to the help manual of putty section 4.18.1

In SSH, you don't have to run a general shell session on the server. Instead, you can choose to run a single specific command (such as a mail user agent, for example). If you want to do this, enter the command in the ‘Remote command’ box.
Note that most servers will close the session after executing the command.

In this case use this field on the GUI to run only one instruction:

enter image description here

  • can this run a command like say putty.exe -ssh [email protected] -pw password -m mkdir /home/user/newflder Feb 24, 2014 at 10:17
  • 1
    @JishnuUNair see the edit ;-)
    – Kiwy
    Feb 24, 2014 at 10:20
  • @Kiwy nice answer +1 :)
    – albciff
    Apr 21, 2016 at 13:15
  • 1
    I needed exactly what you put in the edit regarding the putty "Remote command", should've used this long ago for various tasks on Linux system thru putty from Windows. Jan 8, 2020 at 16:26

Not the answer you're looking for? Browse other questions tagged .