I have a simple script being called from a webpage that grabs a couple fields of information and should put it into a .csv file.

Here's the code:

#!/usr/bin/perl # consent.cgi use strict; use warnings; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use Fcntl ':flock'; use POSIX; #VARIABLES my $sys_time = POSIX::strftime("%D %T", localtime); my $data_path = "/home/account/cgi-bin/asewk"; my $jump_url = "http://mysite.com/ase-workkeys/consent-confirm.html"; my ($which_form, $consent, $user_name, $company, $user_email, @flatfie +lds, $flatfile); #SCRIPT &setValues; &writeCSVfile($which_form, $flatfile); print redirect($jump_url); exit; #SUBROUTINES sub setValues { #get values from form $which_form = param('which_form'); $consent = param('consent'); $user_name = param('name'); $company = param('company'); $user_email = param('email'); #build line for csv flatfile @flatfields = ("$sys_time", "$consent", "$user_name", "$company", +"$user_email"); $flatfile = join(",", map { local $_ = $_; s/"/""/g; qq("$_") } @f +latfields); } sub writeCSVfile { my($filename, $linename) = @_; #name subroutine variables my $log_file = "$data_path/$filename\.csv"; open (LO, ">>$log_file") or die "Could not open $log_file: $!"; flock LO, LOCK_EX; #exclusive lock print LO "$linename\n"; close LO; }

perl -c consent.cgi comes back OK.

This is a new system for me, running a 5.8 flavor of perl (I was previously on 5.004 *shudder*), and initially I was getting this error
Could not open /home/account/cgi-bin/asewk/employer.csv: Permission denied at /home/account/cgi-bin/asewk/consent.cgi line 42.

I chmod'ed all I knew to chmod and then got in touch with my network guys. His response was:

The problem appears to have been caused due to the site running as the 'apache' user, which didn't have write permissions. I modified Apache to run the site as the 'account' user which does have the proper credentials. The CGI runs now, but gives an Internal Server Error, and the logs don't show much. Can you add some debugging to the code to see if the problem is related to something with the server, or if it's code related?

The error logs just show Premature end of script headers: consent.cgi, referer: http://mysite.com/ase-workkeys/employerconsent.html.
Such a non-informative message.

My questions are:

  1. Is there something glaring (like a typo) that I'm missing in my code to throw this error?
  2. If not, then what should I put in for debugging to find out more information?

Thank you!

UPDATE:
After looking in the suexec.log and giving that error to the network admin with my server hosting, he came back with this "solution."

It seems that the issue is that suexec REQUIRES that all executing CGI's be run from (or underneath) /var/www. This means that your current directory organization, eg /home/<something>, etc would have to be moved to something like /var/www/sites/<something> (as an example).

So it was a permissions thing, and not my perl code (though it can admittedly be improved upon.)


I learn more and more about less and less until eventually I know everything about nothing.

In reply to a classic : 'Premature end of script headers' problem by hmbscully

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.