Search code examples
batch-filesshautomationputty

When starting a command using PuTTY commandline it exits without performing the command


I'm trying to automate 1000 SSH sessions linux-based from BAT file and PuTTY v0.75. However, I want when the sessions opened, they execute node.js script in all windows. So, I use this command:

@echo off
for /l %%N in (1 1 1000) do start "" putty.exe -load "iot" [email protected] -pw password -m "D:\Programs\PuTTY\test.txt"

in test.txt:

node pow.js

The problem is that the session opens, and then it exits without performing the command.

Any help?


Solution

  • When you execute the command this way, you cannot see the output it produces. So it's difficult to debug the problem. For debugging it, use Plink instead. With Plink, you will be able to see the errors. Alternatively, enable logging in PuTTY (using -sessionlog)


    From my experience, your problem is that the node cannot be found or it fails because the environment is not set up correctly.

    Why that can be the case, even if you (I hope) are able to execute the same command in an interactive PuTTY terminal, is discussed in these questions:

    They are about Plink, but all that is written there applies to using PuTTY with the -m switch.