CGI NET::SSH browser problem

K

karraso

Hello,
It is my first post to this group, any way.
I wrote script in perl and it is working fine with cmdline, but in cgi it doesn't.
The browser doesn't print any outputs.
###################################################
open(wynik, ">plik.txt");

use Net::SSH qw(sshopen2);


$user = "user";
$host = "host";
$cmd = "/bin/bash";
@commands = ('ls -l');

sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!";
foreach(@commands) {
print WRITER "$_ && echo DDDOOONNNEEE\n";
while (<READER>) {
chomp();
push (@tablica, $_);
last if /DDDOOONNNEEE/;
print "$_\n";

}
}
print wynik "@tablica";

And @tablica is empty when I use cgi. With cmdline the script is working fine, all data are included in @ and in file.
I'm using apache serwer, so maybe there is a problem with userid or access to private key on my pc.

Could you tell me where is the problem? How can I fix it?
BR
karraso
 
J

Justin C

Hello,
It is my first post to this group, any way.
I wrote script in perl and it is working fine with cmdline, but in cgi it doesn't.
The browser doesn't print any outputs.
###################################################

**ALWAYS**
use warnings;
use strict;

and let Perl help you.

open(wynik, ">plik.txt");

Always test whether your 'open' command succeeds:

my $filename = 'plik.txt';
open my $FILEHANDLE, ">", $filename or die "Cannot open $filename: $!";

use Net::SSH qw(sshopen2);

$user = "user";
$host = "host";
$cmd = "/bin/bash";

my ($user, $host, $cmd) = ('user', 'host', '/bin/bash');

@commands = ('ls -l');

my @commands...


Have you checked the server logs? My guess at the reason it's not
working is that you've not given a password, which you've probably done
because you have pre-shared keys set up. But the web-server, which is
the 'user' that runs your program, does not likely run as you and
therefore does not use your pre-shared key. I think you need
authentication of some kind in your program.


Justin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Remote SSH and Configuring code help 0
ssh into remote nodes, do mulitple commands 2
Net::SSH::Expect 7
Problem using Net::SSH::Perl 4
ssh tullen 0
ssh tullen 20
Net::SSH::W32Perl - hanging 0
Net::SSH::Perl question 2

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top