Subject: | 'broken pipe' with commands with large output |
Hi,
I was having issues with Net::SSH::Perl; specifically when I tried to
execute large commands in non-interactive mode with SSH1. In my case, it was
a "show tech" on a Cisco router. The problem was that I would get a broken
pipe error after the command had completed. After investigating, I found
that it was happening at the end of $ssh->cmd, inside $ssh->_disconnect, at
the $packet->send. By elminating the $ssh->_disconnect call I am able to
alleviate the problem.
[root@badonkadonk SSH]# diff -u Perl/SSH1.pm Perl/SSH1.pm.orig
--- Perl/SSH1.pm 2003-12-01 12:28:54.000000000 -0700
+++ Perl/SSH1.pm.orig 2003-11-28 17:34:17.000000000 -0700
@@ -274,7 +274,7 @@
my($stdout, $stderr, $exit) =
map $ssh->{"_cmd_$_"}, qw( stdout stderr exit );
- #$ssh->_disconnect;
+ $ssh->_disconnect;
($stdout, $stderr, $exit);
}
What I believe is the issue is that _disconnect tries to close a socket that
is already closed where as in the case of a quick command it is able to
write to the socket before this happens. The server is sending an
SSH_MSG_EXITSTATUS which according the protocol documents for SSH1, requires
the client to send an SSH_CMSG_EXIT_CONFIRMATION and then close the socket.
By setting up a handler for SSH_MSG_EXITSTATUS I can see that this is
happening. Perhaps testing the socket inside _disconnect before trying to
send a packet would be prudent? I don't know; unfortunately I have not got
the time to look into this any further.
Thank you,
Scott Beuker