Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to use system call within a cgi script

Reply
Thread Tools

how to use system call within a cgi script

 
 
ReggieC
Guest
Posts: n/a
 
      10-10-2008
Hi there,

I have to execute an executable from a CGI script written in perl. I
cannot do that even
with a very simple test like:
$result = system("mkdir test1");
$result = system("mkdir ", "test1");
exec('mkdir test1');
but always got 500 Internal Service Error.

Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.

I'm using perl 5.8 with Apache 2.2.

Any opinion is very much appreciated.
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      10-10-2008
ReggieC <(E-Mail Removed)> wrote:
>Hi there,
>
>I have to execute an executable from a CGI script written in perl. I
>cannot do that even
>with a very simple test like:
>$result = system("mkdir test1");
>$result = system("mkdir ", "test1");
>exec('mkdir test1');
>but always got 500 Internal Service Error.


What does the server log tell you?

>Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.
>I'm using perl 5.8 with Apache 2.2.
>Any opinion is very much appreciated.


Could be many, many, many things. Missing permissions, wrong path,
virtual root folder, ...

See 'perldoc -q 500' for some ideas.

jue
 
Reply With Quote
 
 
 
 
smallpond
Guest
Posts: n/a
 
      10-10-2008
On Oct 10, 4:41 pm, ReggieC <(E-Mail Removed)> wrote:
> Hi there,
>
> I have to execute an executable from a CGI script written in perl. I
> cannot do that even
> with a very simple test like:
> $result = system("mkdir test1");
> $result = system("mkdir ", "test1");
> exec('mkdir test1');
> but always got 500 Internal Service Error.
>
> Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.
>
> I'm using perl 5.8 with Apache 2.2.
>
> Any opinion is very much appreciated.


What is the permission and owner on the directory where you are
trying
to make a new subdirectory and what user are you running as?

 
Reply With Quote
 
Jamie
Guest
Posts: n/a
 
      10-10-2008
In <(E-Mail Removed)>,
ReggieC <(E-Mail Removed)> mentions:
>Hi there,
>
>I have to execute an executable from a CGI script written in perl. I
>cannot do that even
>with a very simple test like:
>$result = system("mkdir test1");
>$result = system("mkdir ", "test1");
>exec('mkdir test1');
>but always got 500 Internal Service Error.
>
>Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.
>
>I'm using perl 5.8 with Apache 2.2.
>
>Any opinion is very much appreciated.


Print out a header first so you can see the problem? Also, try redirecting
stderr to see any error messages.

In "production", I often use system in a list context:

system('/bin/mkdir','path1');

You probably don't want it evaluated by the shell.

Most likely it's a permissions issue.

Jamie
--
http://www.geniegate.com Custom web programming
Perl * Java * UNIX User Management Solutions
 
Reply With Quote
 
ReggieC
Guest
Posts: n/a
 
      10-10-2008
Thanks for info from Jue and Smallpond.

Basically the key is $ENV{"PATH"}="";

After I carefully checked, I missed to declare my $result after
adding $ENV{"PATH"}=""; (I modified and moved lined around
while testing. When I did not have $ENV{"PATH"}=""; I did
have my $result.)

Thanks a lot for the tip of checking logs. The info there tipped
me up. Knowing perldoc -q 500 is useful, too.

Thanks again.


smallpond wrote:
> On Oct 10, 4:41 pm, ReggieC <(E-Mail Removed)> wrote:
> > Hi there,
> >
> > I have to execute an executable from a CGI script written in perl. I
> > cannot do that even
> > with a very simple test like:
> > $result = system("mkdir test1");
> > $result = system("mkdir ", "test1");
> > exec('mkdir test1');
> > but always got 500 Internal Service Error.
> >
> > Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.
> >
> > I'm using perl 5.8 with Apache 2.2.
> >
> > Any opinion is very much appreciated.

>
> What is the permission and owner on the directory where you are
> trying
> to make a new subdirectory and what user are you running as?

 
Reply With Quote
 
Tony Curtis
Guest
Posts: n/a
 
      10-11-2008
ReggieC wrote:
> Hi there,
>
> I have to execute an executable from a CGI script written in perl. I
> cannot do that even
> with a very simple test like:
> $result = system("mkdir test1");
> $result = system("mkdir ", "test1");
> exec('mkdir test1');
> but always got 500 Internal Service Error.


why would you want to go out to a shell for a perl built-in?

perldoc -f mkdir

hth
t
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      10-11-2008
ReggieC <(E-Mail Removed)> wrote:

> Hi there,
>
> I have to execute an executable from a CGI script written in perl. I
> cannot do that even
> with a very simple test like:
> $result = system("mkdir test1");
> $result = system("mkdir ", "test1");
> exec('mkdir test1');


Read perldoc -f exec

Remove the exec, and try again, does it now work?

> but always got 500 Internal Service Error.


Always copy error messages, don't type them yourself.

--
John http://johnbokma.com/ - Hacking & Hiking in Mexico

Perl help in exchange for a gift:
http://johnbokma.com/perl/help-in-ex...or-a-gift.html
 
Reply With Quote
 
Grant
Guest
Posts: n/a
 
      10-12-2008
On 11 Oct 2008 23:25:58 GMT, John Bokma <(E-Mail Removed)> wrote:

>ReggieC <(E-Mail Removed)> wrote:
>
>> Hi there,
>>
>> I have to execute an executable from a CGI script written in perl. I
>> cannot do that even
>> with a very simple test like:
>> $result = system("mkdir test1");
>> $result = system("mkdir ", "test1");
>> exec('mkdir test1');

>
>Read perldoc -f exec
>
>Remove the exec, and try again, does it now work?
>
>> but always got 500 Internal Service Error.

>
>Always copy error messages, don't type them yourself.


I'd add to that, tail -f the error_log in another terminal and make sure
you made the work area world writable -- not particularly safe, is it?

Grant.
--
http://bugsplatter.id.au/
 
Reply With Quote
 
Grant
Guest
Posts: n/a
 
      10-12-2008
On 11 Oct 2008 23:25:58 GMT, John Bokma <(E-Mail Removed)> wrote:

>ReggieC <(E-Mail Removed)> wrote:
>
>> Hi there,
>>
>> I have to execute an executable from a CGI script written in perl. I
>> cannot do that even
>> with a very simple test like:
>> $result = system("mkdir test1");
>> $result = system("mkdir ", "test1");
>> exec('mkdir test1');

>
>Read perldoc -f exec
>
>Remove the exec, and try again, does it now work?
>
>> but always got 500 Internal Service Error.

>
>Always copy error messages, don't type them yourself.


Oops, I meant to add an example, this is from a .cgi here (awk):
....
# create a unique output filename
cmd = "mktemp public/cc2ip.XXXXXX"; cmd | getline out; close(cmd)

# make the output filename world writable and append .txt
system("touch " out " && chmod a+rw " out " && mv " out " " out ".txt")
out = out ".txt"
....

The matching web directory:
-r-sr-xr-x 1 grant wheel 3104 2008-10-05 09:07 cc2ip.cgi*
-rwxrwxr-x 1 grant wheel 11570 2008-10-12 06:35 index.html*
-rwxrwxr-x 1 grant wheel 444 2008-10-05 09:07 lookup-ip*
drwxrwxrwx 2 grant wheel 184 2008-10-12 00:02 public/
drwx-w---- 2 grant wheel 128 2008-10-12 11:32 server/

Access to the server script and directory is restricted by a security
wrapper written in C.

Context: http://bugsplatter.id.au/cc2ip/

Grant.
--
http://bugsplatter.id.au/
 
Reply With Quote
 
Tim Greer
Guest
Posts: n/a
 
      10-14-2008
Grant wrote:

> On 11 Oct 2008 23:25:58 GMT, John Bokma <(E-Mail Removed)> wrote:
>
>>ReggieC <(E-Mail Removed)> wrote:
>>
>>> Hi there,
>>>
>>> I have to execute an executable from a CGI script written in perl.
>>> I cannot do that even
>>> with a very simple test like:
>>> $result = system("mkdir test1");
>>> $result = system("mkdir ", "test1");
>>> exec('mkdir test1');

>>
>>Read perldoc -f exec
>>
>>Remove the exec, and try again, does it now work?
>>
>>> but always got 500 Internal Service Error.

>>
>>Always copy error messages, don't type them yourself.

>
> Oops, I meant to add an example, this is from a .cgi here (awk):
> ...
> # create a unique output filename
> cmd = "mktemp public/cc2ip.XXXXXX"; cmd | getline out;
> close(cmd)
>
> # make the output filename world writable and append .txt
> system("touch " out " && chmod a+rw " out " && mv " out " "
> out ".txt") out = out ".txt"
> ...


You probably don't want to make it world writable unless you have a good
reason, assuming they even need that those of permissions.


>
> The matching web directory:
> -r-sr-xr-x 1 grant wheel 3104 2008-10-05 09:07 cc2ip.cgi*
> -rwxrwxr-x 1 grant wheel 11570 2008-10-12 06:35 index.html*
> -rwxrwxr-x 1 grant wheel 444 2008-10-05 09:07 lookup-ip*
> drwxrwxrwx 2 grant wheel 184 2008-10-12 00:02 public/
> drwx-w---- 2 grant wheel 128 2008-10-12 11:32 server/


Glad to see nothing is setguid there.

World write is indeed sometimes needed for some people, and is fine if
they aren't on a shared server, but I'd just recommend against it if
you're on a server that other users are on.

Anyway, yeah, just check the logs, print the proper header for CGI and
be sure to check your calls and catch (and log or report) any
errors/failures.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Running CGI from within CGI rodmc Python 3 02-14-2008 03:33 PM
what's wrong calling a Perl/CGI script in Perl/CGI script under Tomcat server? kath Perl Misc 4 04-09-2007 09:21 PM
use CGI; vs use CGI qw(:standard); Guy Perl Misc 4 12-11-2003 11:56 PM
How Do I Use CGI->System Call As CronJob? Public Interest Perl Misc 10 10-31-2003 11:00 PM



Advertisments