I want to create an SSH session to a remote machine using Perl, and execute commands automatically from a Windows machine. Is there a way I can do that?
1 Answer
The Net::SSH module relies on a command-line ssh tool, which Windows doesn't have straight from the box.
I suggest you use Putty's plink command instead of putty itself, as plink is much closer to an ssh command-line utility and is intended for this sort of thing. Together with IPC::Open3 (or IPC::Open2 if you're not interested in seeing the output to STDERR) it will let you print commands and and readline the responses interactively. I am sure you can create your own log files.
Alternatively you could consider Net::SSH::W32Perl, which is a compatibility layer around Net::SSH::Perl. It is rather old but should be better than relying on Putty.
Puttyinstead of theNet::SSHmodule?puttyis not a programming question. This belongs on Super User. //puttydoes not accept a command from the command line. A command to execute on connect can be placed in a profile, though. That will only be useful to you always want to execute the same command.sshutility, which is howNet::SSHdoes its thing.