Link to home
Start Free TrialLog in
Avatar of kipper7
kipper7

asked on

Strange Apache/CGI question

running Apache 1.3.6 on a SunOS 5.8 Server. Apache and cgi script were working fine until a few days ago. The scripts run, however when the browser calls it, it only displays some of the data. For instance, if the cgi is supposed to print 100 rows in a table, it prints like 40 and quits.
The scripts are in Perl. Perl version 5.6.1

Any ideas ?

Thanks
Avatar of samri
samri
Flag of Malaysia image

Do you have anything in the error_log?

What is does you script do? I mean, does it connect to external database - mySQL, Oracle.

Could you verify that the execution of the scripts are actually completed, and only 40 rows are there.  Normally what I did is to insert a "debug" marker to figure out which portion of the code is halting the execution.  In perl, I simply insert a

print "I am here now<b>";

Does the scripts runs (OK), if you skip the table output?
most usual the script did not finish within the TCP/IP and/or webserver's timeout.
This might be due to a high load on the server, or a slow connection to the client, or ...
Avatar of kipper7
kipper7

ASKER

Thank you for the responses.

<Do you have anything in the error_log?
no errors !!

<What is does you script do? I mean, does it connect to external database - mySQL, Oracle >

the problem seems to be on a variety of scripts (that used to work fine). Even a simple script to display env variables, does not show all of the data. The other script is a simple cat of a file and parses it and outputs the data. none of the scripts in question connect to a DB.
 
< Could you verify that the execution of the scripts are actually completed, and only 40 rows are there.
 Normally what I did is to insert a "debug" marker to figure out which portion of the code is halting
the execution.  In perl, I simply insert a
print "I am here now<b>"; >

I added a counter to the script and made the final line print the total and the script (from a browser) never makes it there.

< Does the scripts runs (OK), if you skip the table output? >
no, it dies as well.

< most usual the script did not finish within the TCP/IP and/or webserver's timeout.
This might be due to a high load on the server, or a slow connection to the client, or >

i bumped up all of the timeouts on the server end.

I can post the script code if you need.





That surely be helpful, if and only if you feels like posting it.  And I hope, it's not more that 10 lines (just kidding).

Just to get a few more things (just to make sure that it's the script and/or apache) away.

Any changes to the OS recently?

Okay, post the scripts.
Avatar of kipper7

ASKER

WOOPS !!!!!!!!!!!!

actually YES, the script runs ok without the table output !!

Is this getting us somewhere ??

Thanks
Avatar of kipper7

ASKER

Here is the script that quits after about 40 rows
and again if i take out tables and just print the lines it works !!:
------------------

#!/appl1/perl/bin/perl -w

my @users = `rsh fpbea01a cat /etc/passwd`;
my $count;
print "Content-type:text/html\n\n";
print <<START;
<html><head><title>Get Users</title></head>
<body>
START

print <<TABLE;
<table border="1" width="100%">
<tr>
    <td width="33%"><b><u>User Name</u></b></td>
    <td width="33%"><b><u>Full Name</u></b></td>
    <td width="34%"><b><u>Home Directory</u></b></td>
</tr>
<tr>
    <td width="33%">&nbsp;</td>
    <td width="33%">&nbsp;</td>
    <td width="34%">&nbsp;</td>
</tr>
TABLE

foreach  (sort(@users)) {
      my ($login, $pw, $uid, $gid, $gcos, $home, $shell) = split (/:/);
      next if ( $_ !~ /1992/ );
     $count++;
print <<ROW;
<tr>
    <td width="33%">$login</td>
    <td width="33%">$gcos</td>
    <td width="34%">$home</td>
</tr>
ROW

}


print <<TOTAL;
<tr>
    <td width="33%"><b><u>&nbsp;</u></b></td>
    <td width="33%"><b><u>&nbsp;</u></b></td>
    <td width="34%"><b><u>&nbsp;</u></b></td>
</tr>
<tr>
    <td width="33%">Total Users are: $count</td>
    <td width="33%">&nbsp;</td>
    <td width="34%">&nbsp;</td>
</tr>
TOTAL


print "</table>";
print "</body></html>";
I believe so.

I used to have this kind of problem;  some background.  Used to connect to mySQL DB.  If the query syntax is wrong, the pages seems to stop there.

It looks fine to the browser since, the Perl prints a proper HTML header, and proper HTML tag.  Imagine you had this file "test.html"
---
<html>
<head>
<title>Dummy</title>
</head>
<body>
Hi there

---
Notice that the </body></html> is missing.  The page would be displayed anyway.  

This is the beauty of HTML, but headache to debug (my opinion).



Anyway, how do you arrive to generate this "table".  How do you actually pull data from your external data source?

Is it possible to run the script from command line?  If it is, watch the output closely, does it completes, ie. Does it comes to the portion where it is suppose to print the HTML trailer.

It looks like we are going into a loop here.  The point is, check the logic, and set "break-point", and print out debug value in you scripts.  A hint: a simple division-by-zero could could be fatal to you scripts (if running from cmd line), but from CGI, it just dies whenever it reaches that portion, and leave us wandering why it dies.

I hope this could help.  I you could add more, we might be able to eliminate some possibilities.

Are there any "system calls" like "exec" or "system"?  Possible arithmetic, like division-by-zero possibilities? in your scripts.

kipper;

COuld you confirm that the rsh works
my @users = `rsh fpbea01a cat /etc/passwd`;

#!/appl1/perl/bin/perl -w

my @users = `rsh fpbea01a cat /etc/passwd`;
my $count;
print "Content-type:text/html\n\n";
print <<START;
<html><head><title>Get Users</title></head>
<body>
START

print "LOGIN ID<br>\n";
foreach  (sort(@users)) {
     my ($login, $pw, $uid, $gid, $gcos, $home, $shell) = split (/:/);
     next if ( $_ !~ /1992/ );
    $count++;
    print "USER : $login<br>\n";
print "</body></html>";
-------------
This should print the loginID, one per line, nothing else.  If only "LOGIN ID", appears with nothing beneath, we know that the rsh failed.
Missed the closing "}"

   print "USER : $login<br>\n";
}
print "</body></html>";
Avatar of kipper7

ASKER

hmmm...
I tried to add back in some spacing (for formatting) using a bunch of &nbsp
and that messed it up again. very strange.
--------------------------

yes, the rsh command works fine and fills the array with all the members fine.

So we knew that rsh work; that left with the table portion.  I'm not much of a perl coder; but what is "$_" in this statement:

   next if ( $_ !~ /1992/ );

I would presume it is the element extracted from @users array.  The logic only print elements that has "1992" in it.  Perhaps there is users that has UID 1992, or has "1992" word matched anywhere inside the line.

The rest of the codes looks clean.

One possibilities, try to revise the code to print all entries instead of selected records.  If this works, put back the "if" statement.
> yes, the rsh command works fine ..
How did you verify this?

Also try to move the rsh call right behind the very first print command.
guys,

I'll need to put my "cpu" to suspend mode for a while - "sleep" - it's almost 3am here.

I think we should be getting close to closing this.

take care all.
Avatar of kipper7

ASKER

rsh works fine. the fact that if the table and formatting html tags are removed, the script works fine. also from command line, it works fine. and for good measure i tried samri suggestion.
tried moving the rsh command all over the place including behind the first print command..no luck.

if we solve this I will give 300 points to each of you
> > yes, the rsh command works fine ..
> How did you verify this?

Please describe in detail how you verified that it works.
Also describe how it works from command line.

I assume that the cgi Script has problems with the rsh call.
kipper,

the pts surely would be great.

But what puzzled me is that, why the table tag is breaking the HTML output.

I would think that rsh is the culprit.

Anyway, assuming that rsh is OK. Does the output break at certain userid everytime, or at random.  If is does, could you try not to sort the @user (in the for loop).  See whether it break at that user, or after a number or rows.  

I should be able to try to simulate once I'm back in the office.
Avatar of kipper7

ASKER

Ok
again rsh works fine. verified in the fact that :
1. works from command line
2. worked fine using SAMRI suggestion script
3. works fine from browser if formattning is removed.
4. if rsh was the problem, it would not have output at all and the array would have failed, displaying fatal error
---


< I'm not much of a perl coder; but what
is "$_" in this statement:

  next if ( $_ !~ /1992/ );
>

the $_ is a special temp variable that is replaced for every iteration of the loog, could also have named my own temp variable like this:

foreach $user (sort(@users)) {
    next if ( $user !~ /1992/ );
----

< One possibilities, try to revise the code to print all entries instead of selected records.  If this
works, put back the "if" statement.  >

tried that too, did not work. the problem is formatting the data in HTML and is really strange.
Taking out the SORT also makes no difference.
the rows stop BOTH ways after 39 users/rows.




ASKER CERTIFIED SOLUTION
Avatar of samri
samri
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kipper7

ASKER

i have discoverd that the table is not the culprit. seems any sort of HTML formatting added to the iterated print lines causes problems.
It must be some sort of system issue, but i have no idea what it could be. I am going to try to reinstall apache and see if that changes anything.

btw and fyi:  printfs don't work in cgi's

I am closing this for now. and would giving the points to samri. would also like to give points to ahoffman, so please tell me what question i should make up so you can get the points.

thanks again and if you think of anything that could be causing the problem please email me at: james.kipp@mbna.com

thanks
kipper7,  
You can post an empty question in this topic area and allocate the desired pts.  You can use "pts for ahoffman for Q.20292737".

Before you reinstall, see if you could restart the machine, or restart apache first.  I knew this may sound strange, but I do get into scenarios where, restarting the machine kinda "solve" the problem auto-magically.

cheers.
Avatar of kipper7

ASKER

Tried many apache restarts already. This is a huge E10K server that I do not have phyiscal access to. It is rebooted once per month. I guess we will see what happens on the next reboot.

Thanks again
Avatar of kipper7

ASKER

Added question "Points for AHOFFMAN".
kipper7,

Strange, I tested the same scripts on my Rh7.2, it works fine.  The only difference is;

#my @users = `rsh fpbea01a cat /etc/passwd`;
my @users = `cat /etc/passwd`;

perhaps maybe some information in your passwd file that break the <table> tag.  Remember that some properties like homedir, or shell do contain "/", which might have conflicted the HTML tag.
samri, kipper7,
do you mind to continue this question in the other thread?
sure.
Avatar of kipper7

ASKER

Upgraded to 2.0.35 and works fine !!!