[EMAIL PROTECTED] recently wrote (in part):
> The fact your code executes from the command line and not the web
> server indicates either a permissions problme or an environment
> problem.
I'll second that environment problem observation. When something
works from the command line but not as a CGI, that's one of the
first things I check. Here's an ugly Perl script that might
be of use in comparing the two environments.
...BC
--
+----------------------------[ [EMAIL PROTECTED] ]---+
| Bill Costa |
| CIS/TCS -- 1 Leavitt Lane PHONE: +1-603-862-3056 | No good deed...
| University of New Hampshire | goes unpunished.
| Durham, NH 03824 USA |
| |
+-----------------[ http://pubpages.unh.edu/~wfc/ ]---+
#!/usr/bin/perl
#
# File: grok.cgi (and sym-link'd as grok.txt.cgi)
# Author: [EMAIL PROTECTED]
# Abstract: Dump the CGI environment to web browser or shell
# environment to terminal.
#
# Notes: Ugly program for revealing the environment settings
# that Perl CGI script will see. Also works from
# the shell command line for comparison. The
# script's output mode, HTML vs. text, is
# controlled by the name the script was invoked
# with, i.e.
#
# grok.txt.cgi - output information as plain text
# for easier comparison using diff.
#
# grok.cgi - output information in HTML
#
#==============================================================================
use English;
use CGI::Pretty;
$q = new CGI;
$ENV{TEST} = "The script set this environment variable itself...";
#-------------------------------+
# Determine host and the 'mode' |
# we're in. |
#-------------------------------+
my $host = $ENV{'HTTP_HOST'};
my $scrp = $ENV{'SCRIPT_FILENAME'};
my $cmdNam = $0;
my $self = $q->self_url;
my $mode = '';
my $secure = 'not https!';
$secure = "" if (defined($ENV{HTTPS}) and $ENV{HTTPS} eq 'on');
my $realHost;
eval
{
use Sys::Hostname;
$realHost = hostname() || "? unknown ($@)";
};
$realHost = "? unknown host (Sys::Hostname failure)"
if (not defined($realHost));
#-------------------------------+
# Change program behaviour by | $scrp is empty if run from command line.
# looking at our own name. |
#-------------------------------+
if ($scrp =~ m/\.txt.cgi$/i) { $mode = 'TXT' } # still an HTML doc
elsif ($cmdNam =~ m/\.txt.cgi$/i) { $mode = 'txt' } # pure text
else { $mode = 'HTML' } # use HTML typesetting
if ($mode ne 'txt')
{
print
(
$q->header(),
$q->start_html
(
-title=>"$mode: CGI Echo Script",
-style=>{-src=>'http://pubpages.unh.edu/cisunix.css'}
),
);
print("<PRE>\n") if ($mode eq 'TXT');
}
#-------------------------------+
# Print out who we are and how |
# we were invoked. |
#-------------------------------+
if (lc($mode) eq 'txt')
{
print
(
"$mode mode: CGI Environment Settings\n",
"I AM: $cmdNam\n ON: $host ($realHost)\n",
"$self ==> ", $q->code($scrp), "\n",
);
}
else
{
print
(
$q->h1($secure),
$q->h2("$mode mode: CGI Environment Settings"),
$q->p("I AM: ", $q->code($cmdNam), "<BR> ON: $host ($realHost)"),
$q->p("$self ==> ", $q->code($scrp)),
);
}
#-------------------------------+
# Determine real and effective |
# user and group ids and names. |
#-------------------------------+
my $DFMT = "%25s %3s %s\n";
my $lid = getlogin() || '(no value)';
my $rid = scalar(getpwuid($UID));
my $eid = scalar(getpwuid($EUID));
if (lc($mode) eq 'txt')
{
$lid = sprintf($DFMT, 'getlogin', '', $lid);
$rid = sprintf($DFMT, 'real user id', $UID, $rid);
$eid = sprintf($DFMT, 'effective user id', $EUID, $eid);
}
else
{
$lid = "<TR><TD ALIGN='RIGHT'>getlogin</TD>"
. "<TD></TD>"
. "<TD>$lid</TD>"
. "</TR>\n";
$rid = "<TR><TD ALIGN='RIGHT'>real user id</TD>"
. "<TD>$UID</TD>"
. "<TD>$rid</TD>"
. "</TR>\n";
$eid = "<TR><TD ALIGN='RIGHT'>effective user id</TD>"
. "<TD>$EUID</TD>"
. "<TD>$eid</TD>"
. "</TR>\n";
}
my $lastGrp = "";
my $gLabel = "real user group";
my $rgp = ($mode eq 'HTML') ? '<TR>' : '';
foreach my $grpID (sort(split(/ /, $GID)))
{
next if ($grpID eq $lastGrp);
if ($mode ne 'HTML')
{
$rgp .= sprintf($DFMT, $gLabel, $grpID, scalar(getgrgid($grpID)));
$gLabel = '';
}
else
{
$rgp .= "<TD ALIGN='RIGHT'>$gLabel</TD>"
. "<TD>$grpID</TD>"
. "<TD>" . scalar(getgrgid($grpID)) . "</TD>";
$gLabel = " ";
}
$lastGrp = $grpID; # Detects duplicates.
}
$rgp .= "</TR>\n" if ($mode eq 'HTML');
$lastGrp = "";
$gLabel = "effective user group";
my $egp = ($mode eq 'HTML') ? '<TR>' : '';
foreach my $grpID (sort(split(/ /, $EGID)))
{
next if ($grpID eq $lastGrp);
if ($mode ne 'HTML')
{
$egp .= sprintf($DFMT, $gLabel, $grpID, scalar(getgrgid($grpID)));
$gLabel = '';
}
else
{
$egp .= "<TD ALIGN='RIGHT'>$gLabel</TD>"
. "<TD>$grpID</TD>"
. "<TD>" . scalar(getgrgid($grpID)) . "</TD>";
$gLabel = " ";
}
$lastGrp = $grpID; # Detects duplicates.
}
$egp .= "</TR>\n" if ($mode eq 'HTML');
use Cwd;
if ($mode ne 'HTML')
{
my $wdir = sprintf($DFMT, 'working dir', '', cwd());
print("$lid\n$rid\n$rgp\n$eid\n$egp\n$wdir\n");
}
else
{
print
(
$q->table
({border=>1},
$lid,
$rid,
$rgp,
$eid,
$egp,
$q->TR( $q->td({align=>'RIGHT'}, "working dir")
. $q->td()
. $q->td(cwd())
)
)
);
}
#-------------------------------+
# Dump out process environ. |
#-------------------------------+
if ($mode ne 'HTML')
{
print("-" x 75, "\nPROCESS ENVIRONMENT\n", '-' x 75, "\n");
foreach my $k (sort(keys(%ENV)))
{
if ($k ne 'PATH')
{
printf("%25s %s\n", $k, $ENV{$k});
}
else
{
my $name = $k;
foreach my $val (split(/:/, $ENV{$k}))
{
printf("%25s %s\n", $name, $val);
$name = '';
}
}
}
print("\n");
}
else
{
print($q->h2("<HR>Process Environment<HR>"), $q->start_ul);
foreach $k (sort(keys(%ENV)))
{
print $q->li("$k = $ENV{$k}");
}
print($q->end_ul);
}
#-------------------------------+
# Dump out Perl environ. |
#-------------------------------+
if ($mode ne 'HTML')
{
print("-" x 75, "\nPERL MODULE SEARCH PATH\n", '-' x 75, "\n");
my $i;
foreach my $k (@INC)
{
printf("%2d %s\n", $i++, $k);
}
print("\n");
}
else
{
print($q->h2("<HR>Perl Module Search Path<HR>"), $q->start_ol);
foreach $k (@INC)
{
print $q->li("$k");
}
print($q->end_ol);
}
#-------------------------------+
# End page. |
#-------------------------------+
if ($mode ne 'HTML')
{
print("[EOF]\n");
}
else
{
print("</PRE>\n") if ($mode eq 'TXT');
print($q->h3('[EOF]'), $q->end_html());
}
#==[ EOF: grok.cgi ]==