CGI NET::SSH browser problem

Discussion in 'Perl Misc' started by karraso, Nov 10, 2012.

  1. karraso

    karraso Guest

    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
    karraso, Nov 10, 2012
    #1
    1. Advertising

  2. karraso

    Justin C Guest

    On 2012-11-10, karraso <> 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.
    Justin C, Nov 12, 2012
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. loial
    Replies:
    0
    Views:
    385
    loial
    Feb 3, 2009
  2. loial
    Replies:
    0
    Views:
    389
    loial
    Feb 10, 2009
  3. Tench Johnson
    Replies:
    1
    Views:
    276
    Biff Tannen
    Apr 23, 2010
  4. salamond

    net/ssh in ruby. ssh.exec fails

    salamond, Feb 17, 2011, in forum: Ruby
    Replies:
    0
    Views:
    221
    salamond
    Feb 17, 2011
  5. Replies:
    0
    Views:
    79
Loading...

Share This Page