Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > CGI NET::SSH browser problem

Reply
Thread Tools

CGI NET::SSH browser problem

 
 
karraso
Guest
Posts: n/a
 
      11-10-2012
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


 
Reply With Quote
 
 
 
 
Justin C
Guest
Posts: n/a
 
      11-12-2012
On 2012-11-10, karraso <(E-Mail Removed)> wrote:
> 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.

--
Justin C, by the sea.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with htaccess - cgi e fast cgi Luigi Ma Ruby 0 11-21-2007 04:10 PM
File Creation Problem with CGI Scripts in Apache cgi-bin (Fedora Core 3) BestFriend Perl Misc 2 08-21-2006 04:02 PM
Python CGI problem: correct result, but incorrect browser response. Sullivan WxPyQtKinter Python 1 04-07-2006 06:43 AM
I need some help with browser output in ruby cgi - cgi.rb Professor Chen Ruby 0 02-06-2006 07:08 AM
Calling cgi from cgi thru 'system' function. Different behaviour on browser v/s cmd line Shailan Perl 2 12-15-2003 04:26 PM



Advertisments