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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.