Solved

Strange Apache/CGI question

Posted on 2002-04-23
26
363 Views
Last Modified: 2013-11-18
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
0
Comment
Question by:kipper7
  • 12
  • 10
  • 4
26 Comments
 
LVL 15

Expert Comment

by:samri
Comment Utility
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?
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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 ...
0
 

Author Comment

by:kipper7
Comment Utility
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.





0
 
LVL 15

Expert Comment

by:samri
Comment Utility
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.
0
 

Author Comment

by:kipper7
Comment Utility
WOOPS !!!!!!!!!!!!

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

Is this getting us somewhere ??

Thanks
0
 

Author Comment

by:kipper7
Comment Utility
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>";
0
 
LVL 15

Expert Comment

by:samri
Comment Utility
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.

0
 
LVL 15

Expert Comment

by:samri
Comment Utility
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.
0
 
LVL 15

Expert Comment

by:samri
Comment Utility
Missed the closing "}"

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

Author Comment

by:kipper7
Comment Utility
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.

0
 
LVL 15

Expert Comment

by:samri
Comment Utility
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.
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
> 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.
0
 
LVL 15

Expert Comment

by:samri
Comment Utility
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.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:kipper7
Comment Utility
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
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
> > 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.
0
 
LVL 15

Expert Comment

by:samri
Comment Utility
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.
0
 

Author Comment

by:kipper7
Comment Utility
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.




0
 
LVL 15

Accepted Solution

by:
samri earned 300 total points
Comment Utility
Gee, this is taking longer than I expected.

after looking back at the comments, i noticed that you did mention that the scripts was (indedd) working before.

> "Apache and cgi script were working fine until a few days
ago"

If you can recall; between the last "few days", has anything changed.  for example, new users added, any pacthes applied, etc. etc.

The approach might be slightly off current thread that we are going, but assumming everything is OK; rsh , scripts.  The code should have printed the output OK.

Could you try this one; This would give the output without table format (if we still think that table is the culprit).


#!/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 "<pre>\n";
foreach  (sort(@users)) {
   my ($login, $pw, $uid, $gid, $gcos, $home, $shell) = split (/:/);
   next if ( $_ !~ /1992/ );
   $count++;
printf("%8s\t%5d\t%5d\t%20s\t%20s\t%20s\t%10s\n",$login, $uid, $gid, $gcos, $home, $shell);

}
print "<pre>\n";
print "</body></html>";
0
 

Author Comment

by:kipper7
Comment Utility
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
0
 
LVL 15

Expert Comment

by:samri
Comment Utility
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.
0
 

Author Comment

by:kipper7
Comment Utility
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
0
 

Author Comment

by:kipper7
Comment Utility
Added question "Points for AHOFFMAN".
0
 
LVL 15

Expert Comment

by:samri
Comment Utility
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.
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
samri, kipper7,
do you mind to continue this question in the other thread?
0
 
LVL 15

Expert Comment

by:samri
Comment Utility
sure.
0
 

Author Comment

by:kipper7
Comment Utility
Upgraded to 2.0.35 and works fine !!!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now