The difference between the two is that Net::SSH is a wrapper, you have to have ssh installed on the machine where you are using, while Net::SSH::perl is a perl implementation of the entire protocol, so you don't need the ssh program installed on the machine.
The easiest way to issue multiple commands with the code you have is to change $cmd to be a shell (such as '/bin/sh'), and then use WRITER to write a command to the shell, and read the results from READER. You will need a way to determine when the command is finished though, so you can break out of the READER loop..
Untested code, I prefer Net::SSH::perl...
#!/usr/bin/perl use Net::SSH qw(sshopen2); use strict; my $user = "cosmicsoup"; my $host = "mybox.somewhere.com"; my $cmd = "/bin/sh"; my @commands = ('df -k','free','uptime'); sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!"; foreach(@commands) { print WRITER "$_ && echo DDDOOONNNEEE\n"; while (<READER>) { chomp(); last if /DDDOOONNNEEE/; print "$_\n"; } } close(READER); close(WRITER);
Since you are using the version that uses the external ssh command anyway, you could also look at using something like Expect, and just run ssh yourself.
In reply to Re: Net::ssh vs Net::ssh::perl
by jasonk
in thread Net::ssh vs Net::ssh::perl
by cosmicsoup
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |