dataDrone has asked for the wisdom of the Perl Monks concerning the following question:

Hey Folks, I'v got the below code, and it works fine when i run it from the command line, but
when i fire it from the web form it gives me the following in my error_log
------------error log ---------------------
Can't locate Net/Rexec.pm in @INC (@INC contains:  blah blah 
BEGIN failed--compilation aborted
 at /usr/local/apache/cgi-bin/cgitest2.pl line 3.
Fri Aug 17 18:41:06 2001 (Error) Premature end of script headers: 

------ End log -----------------
And yes, i know i should filter the arglist before allowing it to be passed as cmd line args
for the rexec. I'll gladly accept all sugestions there as well.
------------   Code here --------------
#!/usr/bin/perl
use CGI qw(:standard);
use Net::Rexec 'rexec';
$|=1;

foreach $i (1..5) {
        my $varname=uc param("var$i");
        push @arglist, $varname;
}

$rsys = "myotherbox";
$rcmd = "/pathto/my/program @arglist";
$ruser = "username";
$rpass = "password";

($rc, @rcmdOutput) = rexec($rsys, $rcmd, $ruser, $rpass );

print @rcmdOutput;
---------------- eoc -----------------

Replies are listed 'Best First'.
Re: rexec from a cgi vs cmdline
by tachyon (Chancellor) on Aug 18, 2001 at 10:16 UTC

    So now you know the story the *quick and dirty fix* is to add the path the module to @INC at compile time. You can do this using either of these:

    use lib '/path/to/module'; # or you can BEGIN { unshift @INC, '/path/to/module' }

    There is more detail on @INC at Simple Module Tutorial and CGI Help Guide

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Problem Solved
by dataDrone (Acolyte) on Aug 18, 2001 at 20:29 UTC
    OK, Problem solved. Thanks to all. Flog me for not checking but somehow when i installed IPC::Shareable and NET::FTP+Rexec the install used roots very restricted Umask of 077. Once i tried using the modules from an additional UID (with a fair deal of permissions) this became very clear. Any one have any insight as to why the install did that. I used typical install of "perl Makefile.PL, make, make test, make install"

    Thanks again to all. Dan.

Re: rexec from a cgi vs cmdline
by dataDrone (Acolyte) on Aug 18, 2001 at 04:58 UTC
    Ok, some clarification. I realize the meaning of the 'not in @INC' error which is why i phrased the question "Why does this work from my shell and not when it's triggered by apache" which is of course running as user nobody. Does perl use the calling users $PATH variable to go looking for modules? I'm fairly certain that i installed the modules (as root) using the regular process without any errors. Shouldn't 'nobody' be able to use them?
      I just had a similar problem myself and found out the problem was linked to two installations of Perl on the same machine, in different directories, with different @INC. The @INC from the command line and the @INC from the CGI were different, and voila. The key is to go to /usr/bin/ (or wherever your main installation is) and do a ./perl -MCPAN -e shell to make sure the modules are installed in the proper @INC. (Of course, you could always just move the modules around manually, but I prefer the easy way. :-D)

      Gary Blackburn
      Trained Killer

        Ok, Last night i printed out the @INC's from a cgi triggered script and from root's command line and found them to be identical. I then searched through the @INC paths and found the Rexec.pm nodule and checked it's permissions. It is world readable. I didn't (yet) check all the directories leading up to that but will as soon as i get a chance to telnet (SSH) into work (the box in question). In the mean time i'll try the whole shebang on the laptop (which has a very similar install of Linux) and see if it works or not. Thanks for the efforts, Dan.
      No, Perl does not use $PATH to find modules. It searches the directories in @INC, which are set up when you compiled Perl. You might have been modifying @INC by setting your PERL5LIB environment variable. You might also have put this module in a directory where user nobody doesn't have permission to see them. Or, it might work from command line because @INC includes your current working directory ("."), and the module you need happens to be there.

      You might just want to print out the contents of @INC from command line and CGI and compare what's in them.