The SSH protocol allows for two modes of operation:

The first one is the interactive mode, designed to "talk" with humans, that just launches a shell and attaches it to the SSH channel, that is expected to be attached to the user console in the computer running the SSH client.

The second mode, allows to run independent commands. When it is used, the SSH server runs the given command attaching its IO streams to the SSH channel. It is what you get, for instance, when you run

$ ssh my.unix.box cat /etc/passwd
and it is the mode used by Net::SSH::Perl for its cmd method.

Unfortunately, some servers (as probably the one you are using) do not support this mode and unconditional launch a new shell for every new channel created.

To work-around that, you have to talk directly to the shell, and for that Expect is your best option, or even Net::SSH::Expect that is a wrapper around Expect specifically designed to talk to SSH servers.

... but Expect does not work on Windows, well, it doesn't work with ActiveState Perl (or AFAIK, with Strawberry Perl), but it works with Cygwin Perl.

Probably, Net::SSH::Perl (or Net::SSH2) have low level methods allowing to handle an interactive conversation with a channel, but it's not going to be as easy as with Expect!

update: and BTW, Net::SSH::W32Perl was a hack to make old versions of Net::SSH::Perl work under Windows. AFAIK, its logic was incorporated into the main module and so it shouldn't be used anymore.


In reply to Re: Unable to run command on Cisco switch by salva
in thread Unable to run command on Cisco switch by 1wax

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.