Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

system call in cgi/perl script on linux

by roseberry123 (Acolyte)
on Jun 17, 2004 at 13:17 UTC ( [id://367605]=perlquestion: print w/replies, xml ) Need Help??

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

Hi,

When I make a system() call in a cgi/perl script, the program being called is not executed--that is, when I open the .cgi file with a web browser, nothing happens (and no errors either), I just get a blank screen.

When I try the same system() command in a normal perl script, everything works fine.

Does this have anything to do with the location of the program? I use the absolute path to the program as argument to system(), but it doesn't help.

I'm not sure what other information I should provide.

Any help much appreciated.

Thank you, rb123

  • Comment on system call in cgi/perl script on linux

Replies are listed 'Best First'.
Re: system call in cgi/perl script on linux
by kutsu (Priest) on Jun 17, 2004 at 13:28 UTC

    Providing some small sample code would help, as for the actually problem check your (server's) error logs for any errors. Also check to see that Content-Type: text/html\n\n is being printed before your html.

    "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

Re: system call in cgi/perl script on linux
by Roger (Parson) on Jun 17, 2004 at 13:31 UTC
    Did you check your web server log? Does it have any errors?

    Could it be a permission problem? You need to remember that your cgi program is run under a different user than yourself (the httpd or apache user if you are on a unix machine). The permission problem is the one that usually bites. One way to test this is to setuid to the web server user, and run the cgi script again.

    There are other possible causes too, but check the permission first.

      Thank you. I'm so confused.

      I think the problem is because the program that system() is calling is a bash script, so yes, the permissions and directories are all messed up. I'll probably have to do it by trial and error...

      I was wondering if you could please tell me that if the cgi program (or rather the bash script the cgi program is calling) has to write a file, what permissions do I have to set the directory (where the file will be put) to?

      Thanks very much,
      roseberry

        Step 1 - Find out the user name and group that the web server is running under.

        ps -ef | grep httpd # this will show you the user id of the web server

        Step 2 - Find out the permission of the directories and files you are trying to read from and write to.

        ls -al /my/path

        Step 3 - Change the group of your directory and files to the httpd user group, and set group read/execute permission on the directories and files.

        # httpd group (you can find out from the /etc/password # and /etc/group files chgrp -R httpd /my/path chmod -R g+rx /my/path

        Step 4 - Well, test again.

        su - httpd # set uid to httpd user, assuming that you are the # root user and no password is required # run your cgi script from the command line. # you don't need to use a browser to test the cgi script.

        By the way, you do have root access to the system, don't you?

Re: system call in cgi/perl script on linux
by bibo (Pilgrim) on Jun 17, 2004 at 13:29 UTC
    This has to do with the security environment of the webserver. Your perl script running as cgi in the webserver may (and should!) have less access to the machine resources than a command-line shell. You need to research the web server and CGI configuration of the webserver in order to get your CGI to work. Tell us the webserver name and version, operating system, etc and more pointed suggestions can be made to help you.
Re: system call in cgi/perl script on linux
by ambrus (Abbot) on Jun 18, 2004 at 08:26 UTC

    If the script is running in tainted mode, you'll have to delete $ENV{PATH}; first. If perl runs in taint mode, it won't allow you to system while you have $ENV{PATH} inherited from the environment.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://367605]
Approved by kutsu
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-04-25 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found