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

Hi to all, This is my first post... I'm calling shell script inside my perl script like below. SHELL:~/apache/apache_1.3.41/cgi-bin 5> cat stage1ucmjoin #!/usr/bin/perl print "Content-type: text/plain\r\n\r\n"; if (length ($ENV{'QUERY_STRING'}) > 0){ $buffer = $ENV{'QUERY_STRING'}; @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ s/%(a-fA-F0-9a-fA-F0-9)/pack("C", hex($1))/eg; $in{$name} = $value; } } $streamname = $in{'streamname'}; $isdynamic = $in{'isdynamic'}; if ($isdynamic) { $shellcommand = "ucmjoin -join -dev dynamic -release $streamname"; } my $output = `$shellcommand`; print "\nstatus=$?\n"; print "\n$output\n"; Issue is execution of shell script is failing always when i call inside perl script. I'm calling this perl script from cgi based user interface. But it is working fine while running in command prompt. Please help me to solve this issue... Thanks in advance. -Siva
  • Comment on Execution of shell script failing always inside cgi based perl program

Replies are listed 'Best First'.
Re: Execution of shell script failing always inside cgi based perl program
by marto (Cardinal) on Jan 08, 2010 at 06:31 UTC

    Firstly, welcome to Perl Monks. Secondly, when posting there is advice displayed on how to format your post correctly, to make it easy for everyone to read. Please don't ignore this advice. For further info see How do I post a question effectively?.

    Looking at your code the first thing I'd say is that you don't have:

    use strict; use warnings;

    anywhere. This should be at the start of your script, after the shebang line. Read Use strict and warnings from the tutorials section.

    Is there a reason you aren't using CGI? See Ovid'sCGI Course and CGI Programming from the tutorials section of this site.

    Have you checked the Apache error_log file to see what it says? It's a good place to start investigating such issues :)

    Common reasons for shell scripts not running via CGI scripts include:

    Insufficient privileges: does your shell script work from the command line when executed as the user running your web server/CGI scripts?

    OS based security: Some web servers such as IIS6 won't execute shell or command line scripts out of the box. Is your web server configured correctly? Are you (or more to the point the server on which this script resides) running Security-Enhanced_Linux?

    Martin

Re: Execution of shell script failing always inside cgi based perl program
by cdarke (Prior) on Jan 08, 2010 at 08:35 UTC
    ...and another common reason is that the environment might not be the same, generally this comes from startup files like .profile.

    failing always
    is not very helpful. How does it fail, and what are the error messages (if any)?