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
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |