Hi Monks

I installed the Net::SSH2 module from PPM and trying to connect to remote unix host from windows OS. After running the below code i am getting Error "LINE : Error: "pwd" is not a recognized command"

Below is the code and also the test result once after running the script.I unable to judge weather the script actually succeeded in connecting the host and failed only in executing the the command which i have assigned for $cmd variable in script.Monks, please assist me to figuring out what is actually happening and correct me where i am doing wrong in the script.This is my first post, please ignore if i have not fallowed any posting standards here.
BEGIN { push(@INC,'C:\Perl64\site\lib'); } use warnings; use strict; use NET::SSH2; sub is_sshalive; my $host = "XXXX"; # use the ip host to connect my $user = "yyyy"; # your account my $pass = "zzzz"; # your password my $cmd; my $ssh2 = Net::SSH2->new(); $ssh2->debug(1); if ($ssh2->connect($host)) { if ($ssh2->auth_keyboard($user,$pass)) { print "\n Executing command...\n"; $cmd = "pwd"; print " ==> Running $cmd\n"; if(is_sshalive($ssh2) == 1) { print "\nSSH connection died"; exit 1; } else { run_testsuite($cmd, $ssh2); } } else { warn "ssh auth failed.\n"; exit 1; } } else { warn "Unable to connect Host $host \n"; exit 1; } print "test passed done 0\n"; sub run_testsuite { my $cmd = $_[0]; my $ssh2 = $_[1]; my $chan2 = $ssh2->channel(); $chan2->shell(); print $chan2 "$cmd \n"; print "LINE : $_" while <$chan2>; $chan2->close; return 0; } sub is_sshalive { my $ssh2 = $_[0]; if ($ssh2->poll(1000) == 0) { return 0; # passed } else { return 1; #failed } } Below is the partial test result where it is displaying Error Net::SSH2::Channel::read(size = 1, ext = 0) - read 1 bytes - read 1 total LINE : Error: "pwd" is not a recognized command Net::SSH2::poll: timeout = 250, array[1] - [0] = channel - [0] events 1 - libssh2_poll returned 1 - [0] revents 1 Net::SSH2::Channel::read(size = 1, ext = 0)

In reply to Problem in connecting to remote unix host via Net::SSH2 from windows machine by Perl_abcd_monk

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.