Click to See Complete Forum and Search --> : CGI Header Error


jennAshton
08-01-2003, 04:50 PM
Hello,

In need of CGI help. I wrote a CGI script to do recursive file copy and it works when I execute the script via *nix command. When I tried to to run the script via browser it gave me a 500 error and my error log prints:

[01/Aug/2003:14:37:53] failure (13904): for host xxx.xxx.xxx.xx trying to GET /cgi-bin/myscript.pl, cgieng_scan_headers reports: the CGI program /usr/local/htdocs/cgi-bin/myscript.pl did not produce a valid header (program terminated without a valid CGI header. Check for core dump or other abnormal termination)

Below is my script:

#! /usr/bin/perl
use File::Find;
use File::Copy;
use File::Path;

my $top_src = "/usr/local/htdocs/directory/copyfrom/";
my $dest = "/usr/local/htdocs/directory/copyto/";

find sub {
##might need it for later on
##ignore non html files
return unless -f ;

my $more_subdir;
for ( $more_subdir = $File::Find::dir) {
s#^\Q$top_src##;
s#^/##;
}

## don't copy if we already have a later file
if (-e "$dest/$more_subdir/$_" and -M "$dest/$more_subdir/$_" <= -M
$_) {
## tracing: turn off when you're happy
## warn "ignoring older $File::Find::name\n";
return;
}

mkpath( ["$dest/$more_subdir"], 0, 0775); # $dest must be an absolute

## tracing: turn off when you're happy
##$content = warn "copying $File::Find::name to $dest/$more_subdir/$_\n";
copy $_, "$dest/$more_subdir/$_";
}, $top_src;

exit;



Thanks,

Jenn

Jeff Mott
08-01-2003, 09:17 PM
CGI scripts always need to return an HTTP header. And this must be done before anything else is printed to STDOUT.print "Content-Type: text/html\n\n";oruse CGI;
my $cgi = CGI->new();
print $cgi->header();The latter can be more useful in larger CGI applications, but rather redundant in your case. The first example should suit you fine.

jennAshton
08-04-2003, 12:08 PM
I will give it a shot. Thank you Jeff.

Jenn