Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

CGI Script Working fine from my command prompt but Shows Internal server error when called through browser

by Anonymous Monk
on Dec 26, 2012 at 13:03 UTC ( #1010377=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

my CGI script:
#!/ms/dist/perl5/bin/perl5.8 $p=do("$ENV{PWD_FILE_PL}") or die "Failed to run the PWD_FILE_PL !\n"; foreach my $key (keys %$p) { $ENV{$key}=$p->{$key}; } require "${LIB_PROGDIR}/k_db2_connect.pm"; require "${LIB_PROGDIR}/k_syb_connect.pm"; use MSDW::Version 'DBI' => '1.602', 'DBD-DB2' => '1.0-8.2.7', 'DBD-MSDB2' => '1.3', 'MSDW-DB2-DBInfo' => '1.7', 'Spreadsheet-WriteExcel' => '2.37', 'Parse-RecDescent' => '1.94', 'MIME-Lite' => '2.117', 'Env-Modulecmd' => '1.2', 'Getopt-Long' => '2.37', 'Date-Calc' => '5.3', 'Tie-IxHash' => '1.21', ; use Env; use DBI; use Spreadsheet::WriteExcel; use Parse::RecDescent; use MIME::Lite; use Env::Modulecmd; use Getopt::Long; use Tie::IxHash; use DBD::MSDB2; use strict; use Date::Calc qw(:all); my $my_PID=$$; my $my_env=$ENV{runningEnv}; use Env::Modulecmd { load => "$DB2_CLIENT" }; my @ary = DBI->available_drivers (1); my (@data_exclude,@data_exclude1); my $cnt; my $dbh = _dbinit( 'Sybase',$ENV{DB_SERVER},$ENV{DB_NAME}); my $sth1 = $dbh->prepare("SELECT dbo.cts_registry.value FROM AIS_job_c +ontrol.dbo.cts_registry where dbo.cts_registry.AppName='SSI_MODEL_EXC +LUSION'"); $sth1->execute()or die "ERROR: Can not EXECUTE the SQL statement"; while(@data_exclude=$sth1->fetchrow_array) { $data_exclude1[$cnt]=$data_exclude[0]; $cnt=$cnt+1; } _dbdisconnect($dbh); print "$data_exclude1[1]";
HTML Script:
<form action="db_connect.cgi" method="GET"> <input type="checkbox" name="lights" value="on"> Lights <input type="checkbox" name="camera" value="on"> Camera <input type="submit" value="Do it"> </form>
The Script n html are in same folder..The cgi works fine when i on command prompt but shows 500 internal server error when i run through browser.. Please suggest. Thanks in Advance.

Comment on CGI Script Working fine from my command prompt but Shows Internal server error when called through browser
Select or Download Code
Re: CGI Script Working fine from my command prompt but Shows Internal server error when called through browser
by ww (Bishop) on Dec 26, 2012 at 13:15 UTC
    Did you bother to read (google) the meaning of a 500 error?

    Have you read your server log?

    Under what ID is the server running your code? (Hint: it's likely not the same ID as when you exectue the code from the command line).

    Really important hint: read the instructions around the text entry box! They tell you to wrap your narrative in <p>...(narrative goes here) </p> tags... and your code (so we can read it conveniently) in <code... (code here) </code> tags.

Re: CGI Script Working fine from my command prompt but Shows Internal server error when called through browser
by Anonymous Monk on Dec 26, 2012 at 13:28 UTC
Re: CGI Script Working fine from my command prompt but Shows Internal server error when called through browser
by blue_cowdawg (Monsignor) on Dec 26, 2012 at 20:05 UTC
        use MSDW::Version 'DBI' => '1.602', 'DBD-DB2' => '1.0-8.2.7', 'DBD-MSDB2' => '1.3', 'MSDW-DB2-DBInfo' => '1.7', 'Spreadsheet-WriteExcel' => '2.37', 'Parse-RecDescent' => '1.94', 'MIME-Lite' => '2.117', 'Env-Modulecmd' => '1.2', 'Getopt-Long' => '2.37', 'Date-Calc' => '5.3', 'Tie-IxHash' => '1.21', ;

    Ahhh... someone programming in the Morgan Stanley environment!! I recognize that pattern! :-)

    Any time you get a 500 error from a web server it means that the CGI environment encountered something it could not deal with ranging from straight up Perl syntax errors or other failures to compile to file permissions. Your best bet is to check the server error logs and see what it is really complaining about.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Help required for CGI Script
by Anonymous Monk on Dec 27, 2012 at 08:59 UTC
    My CGI script:
    #!/ms/dist/perl5/bin/perl5.8 -w BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp('fatalsToBrowser'); } use strict; use warnings; use CGI::Carp qw/fatalsToBrowser/; use Env; use lib; use CGI qw( :html3 ); use CGI::Carp qw(fatalsToBrowser); my $q = CGI->new; print $q->header(); print "Hello, world!"; my $stat = `autostatus -J aa-test-bx-dly`; print "\nHI $stat\n"; open(FH1,">/tmp/ac.txt") or die "Cannot create file"; close(FH1); chmod 0777, "/tmp/ac.txt"; open(DAT,">>/tmp/ac.txt"); print DAT "TEST JOB aa-test-bx-dly $stat"; close(DAT); open(CATFILE,"/tmp/ac.txt") || die("Cannot Open File"); my(@catfile) = <CATFILE>; close CATFILE; print "\n\n$catfile[0]\n\n";
    My HTML script:
    print "content-type: text/html \n\n"; <FORM action="../../cgi-bin/test_1.cgi" method="POST"> First Name: <input type="text" name="first_name"> <br> Last Name: <input type="text" name="last_name"> <input type="submit" value="Submit"> </FORM>

    The code shows status when run on command prompt but doesnot show the status of job when run on browser.I am putting it in file , but still it has correct status in file, but when on browser it loses status

    Please suggest.
      my $stat = `autostatus -J aa-test-bx-dly`;

      Perhaps autostatus doesn't live in $PATH for whichever user the CGI process runs as.

        So what should i do

      Likely, the user your CGI script runs as is not the user you are using from the command line. Or maybe the web server user does not have access to the autostatus program because $ENV{PATH} is set up differently under your web server than it is for your command prompt. You never check the result/error status of your backtick call.

      As a first and easy try, I would attempt to give the full path to autostatus instead of hoping that $ENV{PATH} is set up as it is for your shell account.

        I have given the full path , still that doesnot work.
      When you run it via a browser, does your script return "Hello, World!" to the browser, and does the file "/tmp/ac.txt" contain what you expected? Do you see the word "HI"? What does that file contain (what is the expected output from "autostatus -J aa-test-bx-dly")?

      Since you are using "fatalsToBrowser", are you seeing any error messages? What do they say?

      Your code only tries to print the first line of "/tmp/ac.txt" to the browser, but if the output begins with a blank line, that's all your program will send to the browser.

      If the autostatus output contains angle brackets, then your browser will be trying to interpret it as HTML tags, and will probably not display any of it (because the data can't be parsed that way). In order to see the "autostatus" output presented, you may have to print a <pre> tag before printing the command output, and then print a </pre> tag afterwards.

        The output expected is RUNNING or SUCCESS .. Also the file so created doesnt have any blank lines. Please guide me the solution. Thanks

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2014-11-28 14:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (197 votes), past polls