I think I misread your code and sample output anyway. You are getting connected, but the connection isn't doing what you want? Is that closer to what's happening?
A quick note regarding Net::SSH::Perl and myself: I'm no expert on this project, and I won't claim to be. I'm hoping if you haven't stumbled over some solution on your own that more feet will stumble faster. :-)
What happens if you use a command other than 'exit'? My first guess is that you're not getting the command you think you are. An explanation of that thought will be below, but checking the return values on functions (especially those involving more than one machine) should probably be a habit. My guess after that, I think, would be that the exit command on your remote end doesn't close the connection, which you'd have to do manually. Does the connection get closed when you issue the exit command when ssh'ed in directly?
I'm not sure if you've tried it already, but there's Net::SSH, Net::SFTP, and Net::SSH::Perl mailing list that's archived at the modules' Sourceforge project. There's a good chance someone there might have had similar issues. Please let us know if you find something there that helps.
I notice you're not checking the return value on the cmd() method. According to a message on the afore-mentioned archive, at least one person thinks shell builtins don't work with cmd(). I'd guess the exit command wouldn't be a separate executable. Over on CPAN::Forum this message alludes to needing use_pty enforced on cmd() as well as shell() in order to use a shell on the remote end non-interactively. Net::SSH::Perl::SSH2 appears not to do this, and in fact a quick check of Net::SSH::Perl would seem to confirm it.
Given the above information, I'd try using the shell() method and typing 'exit' as a command interactively just to make sure it works there. If that works and I really needed to make it work from the cmd() method, I'd figure out what it so different between shell() and cmd(). Then perhaps I'd subclass Net::SSH::Perl::SSH2 to make cmd() a little more like shell(), or send a patch to the maintainers that enables such use.
|