20
8
I am using the following to login automatically to a remote server and then run commands listed in a commands.txt
, like this:
C:\path\to\putty.exe -load "[Sessionname]" -l [user] -pw [password] -m C:\path\to\commands.txt
commands.txt
contains the following:
ps -elf|grep 'sometext'
However, when I try to do so a new window for PuTTY appears, but it closes and exits instantly after login. As a result, I cannot see the output of the command(s).
I don't understand what's going on here. Am I wrong in my approach or do I need to take more steps to make the PuTTY window pause for some time before exiting?
2Consider to use Plink.exe instead (typically bundled with Putty, remember to include in PATH). I spent 2 hours googling how to specify rsa key in a command line for PuTTY because it's unsafe to hard code passwords. I overlooked Plink solution because, I thought the call had to start with putty. Check answer below mentioning Plink. e.g. `Plink.exe -ssh host -l user -i c:\Users\myName.ssh\myGeneratedPuttyKey.ppk – Soren Havelund Welling – 2016-11-22T14:55:36.943