Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PERL CGI script waits until complete to write webpage 1

Status
Not open for further replies.

chance42

Technical User
Aug 5, 2004
22
US
Hello all,
I am in the process of rewriting a script that was originally written in ksh, on a Solaris box,
then forced to move to a Windows server I began writing it in PERL, due to network restrictions
I have been able to move back to the original Unix server... The script itself connects to two
groups of servers to gather statistical data.
My question is: While running on the Windows server, the script ran as as expected and updates
the web page as it goes, but on the Unix server the script waits to output anything
until the entire script completes. Is there something I missing here? below is the code for
the main script.
It's rough and ugly, so be prepared...
Code:
#!/usr/bin/perl -w
use CGI qw/:standard/;

print ("Content-type: text/html\n\n");
print ("<html>\n<head>\n<title>Stats Gatherer</title>\n");

print ("\n");
print ("</head>\n<body>\n<font face=\"arial\">");
print ("<center><b>This entire process will take approx. 6 minutes.</b><br />\n");
print ("Do not close or reload this page while running or you will have to start over.<br /><br />");

`touch /tmp/stats.lock`;

our @STATSRVRS=("server01", "server02", "server03", "server04", "server05", "server06");
our @P2SRVRS=("server01p2", "server02p2", "server03p2", "server04p2", "server05p2", "server06p2");
our $BC1=@STATSRVRS;
our $BC2=@P2SRVRS;
our $BT=$BC1+$BC2;

`rm /tmp/collect-*`;

print ("\n\nTotal boxes to connect to: <b>$BT</b></center>\n\n\n\n");
print ("<pre>");
print ("\t\t<u>Connecting to boxes</u>:\n\n\n");
#####################################################################
foreach $BOX (@STATSRVRS)
 {
   print ("\t\t\t$BT. <b>$BOX:</b> \t\t");
   our $fail = `/var/apache/cgi-bin/stats/collect.tcl $BOX $UserID $PASS no 2> /tmp/collect-$BOX.err`;
   if ($? == 0)
     {
       print ("<font color=\"green\">Success</font>\n");
     }
     elsif ( -e "/tmp/collect-$BOX.err" )
     {
      my $CS=`tail -1 /tmp/collect-$BOX.log`;
      chomp($CS);
      print ("<font color=\"red\">$CS</font>\n");
     }
   $BT--;
 }
#####################################################################
foreach $BOX (@P2SRVRS)
 {
   print ("\t\t\t$BT. <b>$BOX:</b> \t");
   our $fail = `/var/apache/cgi-bin/stats/collect.tcl $BOX $UserID $PASS yes 2> /tmp/collect-$BOX.err`;
   if ($? == 0)
     {
       print ("<font color=\"green\">Success</font>\n");
     }
     elsif ( -e "/tmp/collect-$BOX.err" )
     {
      my $CS=`tail -1 /tmp/collect-$BOX.log`;
      chomp($CS);
      print ("<font color=\"red\">\t$CS</font>\n");
     }
   $BT--;
 }
#####################################################################
print ("\n\n");
print ("</pre>");



print ("\n\n</body>");
print ("\n</html>\n");
`rm /tmp/stats.lock`;

Thanks for any advise offered,

Mike
 
The windows server must not be buffering the output. You can try unbuffering the output in your script by putting this line in the script before printing anything to the screen:

Code:
$|=1;

I am not sure how it will work with your shell stuff but give it a try.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thank you KevinADC, that did the trick.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top