First off, I'm not a competent Perl coder, so please forgive me if this is obvious....
I'm trying to get the following code to execute two commands on a remote machine using Net::OpenSSH. I can login and execute the first command ok, but the second command simply returns "Connection to x.x.x.x closed by remote host." By introducing a delay before the 2nd command and looking at netstat I can see that the connection is still open, right up until the second command is attempted. In fact netstat looks like:
Is it even possible to execute two commands without opening two connections to the remote machine? Where am I going wrong?! Thanks Monks!netstat -an | grep x.x.x.x tcp 0 0 x.x.x.x:55942 x.x.x.x:22 ESTABLISH +ED unix 2 [ ACC ] STREAM LISTENING 7356830 /home/cstron +g/.libnet-openssh-perl/root-10.224.138.142-26229-724671
#!/usr/bin/perl use Net::OpenSSH; $ip="x.x.x.x"; $user="xx"; $pass="xx"; ($ssh)=&connect_ssh($ip, $user, $pass); @arry = $ssh->capture("ps -ef"); while (@arry) { $line=shift @arry; print "MATCH1 $line"; } @arry = $ssh->capture("ps -ef"); while (@arry) { $line=shift @arry; print "MATCH2 $line"; } sub connect_ssh { my $ip = shift; my $user = shift; my $pass = shift; my $ssh = Net::OpenSSH->new( $ip, strict_mode => '0', user => $user, password => $pass, timeout => '60'); return ($ssh); }
By the way, I know running twp "ps -ef" is pointless, but I'm just trying to illustrate the fact that I can't get a second command to run.
I have openssl installed and normal ssh works perfectly fine.openssl version OpenSSL 0.9.8g 19 Oct 2007
In reply to Net::OpenSSH multiple commands by cstrong
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |