I have given the Linux module for the script below

There doesn't appear anything implicitly wrong with the way you're calling ssh, meaning it should work if the host/user/pass is valid, but @ARGV isn't normally set under CGI

So the problem could be that
your webserver is running your perl cgi program under a user which doesn't have required permissions (limited account, not member of some group ... )
your firewall is interrupting the perl program (or your webserver) from creating outgoing sockets
connecting to a remote server is taking too long, and your webserver is killing your perl program before it is finished

Solution? Check the logs, check the event viewer, check the firewall logs, get/give permissions or make member of group, change timeout or use Proc::Background and Watching long processes through CGI (Aug 02)

But code like you posted is harder to debug/maintain/copy. Don't write code like that, write code like this

#!/usr/bin/perl -- use strict; use warnings; use Devel::CheckOS qw(os_is); use Getopt::Long qw/ GetOptionsFromArray /; use Data::Dump qw/ dd /; Main( @ARGV ); exit( 0 ); sub Main { dd( \@_ ); my %opts = ( prefix => 'C:/Bounce', # default ); GetOptionsFromArray( \@_, \%opts, q{username|user|u=s}, q{password|pass|p=s}, q{host|h=s}, q{prefix|pre=s}, q{cdto=s}, q{cdto=s}, ); dd( \@_, \%opts ); RunForThisOS( info => "$opts{prefix}/$opts{host}.txt", user => $opts{username}, pass => $opts{password}, host => $opts{host}, cdto => $opts{cdto}, prefix => $opts{prefix}, debug => 1, cmd => "cd $opts{cdto} && ./startServer.sh @_", ); } sub RunForThisOS { if( os_is('Linux')){ goto &MyLinuxRun; } die "Unsupported OS"; } sub MyLinuxRun { my( %o ) = @_; exit dd( \%o ); # don't exit use autodie qw/ open close /; open my($INFO), '>', $o{info}; # autodie will die on error print $INFO join "\n", # consider using dd $o{info}, $o{host}, $o{cdto}, $o{cmd}, "\n"; my $ssh = Net::SSH::W32Perl->new( $o{host}, protocol => 2, debug => $o{debug}, ); $ssh->login( $o{user}, $o{pass} ); my($stdout, $stderr, $exit) = $ssh->cmd( $o{cmd} ); print $INFO dd( { stdout => $stdout, stderr => $stderr, exit => $exit, },), "\n"; close $INFO; } __END__

So that when you run it, you get output like

$ perl writeCodeLike.960945.pl -u user -p pass -h host -pre=refix -cdt +o ccddttoo argyargyarg [ "-u", "user", "-p", "pass", "-h", "host", "-pre=refix", "-cdto", "ccddttoo", "argyargyarg", ] ( ["argyargyarg"], { cdto => "ccddttoo", host => "host", password => "pass", prefix => "refix", username => "user", }, ) { cdto => "ccddttoo", cmd => "cd ccddttoo && ./startServer.sh argyargyarg", debug => 1, host => "host", info => "refix/host.txt", pass => "pass", prefix => "refix", user => "user", }

Then when trying to debug only the linux portion, you can write

sub Main { MyLinuxRun( cdto => "ccddttoo", cmd => "cd ccddttoo && ./startServer.sh argyargyarg", debug => 1, host => "host", info => "refix/host.txt", pass => "pass", prefix => "refix", user => "user", ); }

The free Modern Perl book cover many of these tips

See also Devel::CheckOS, Getopt::Long, Data::Dump


In reply to Re: Net::SSH::W32Perl is not working with CGI Perl script by Anonymous Monk
in thread Net::SSH::W32Perl is not working with CGI Perl script by premal

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.