You want Net::SSH or Net::SSH::Perl which is pure Perl and does not shell out to ssh(1)
use Net::SSH qw(sshopen2); use strict; my $user = "username"; my $host = "hostname"; my @cmds = ( "command1", "command2", "etc" ); my %results; for my $cmd ( @cmds ) { sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $! +"; my $result = ''; $result .= $_ while <READER>; $results{$cmd} = $result; } close READER; close WRITER;
This will build a hash $results with the key:value pairs of the command and its result. Note you will lose results if you exec exactly the same command twice as hash keys are unique. If you just want an array of the results do:
my @results; for my $cmd ( @cmds ) { sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $! +"; my $result = ''; $result .= $_ while <READER>; push @results, $result; }
Note if you don't want to use DSA or RSA and wish to supply a login password use Net::SSH::Perl
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: interact with remote host via bastion
by tachyon
in thread interact with remote host via bastion
by jaco
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |