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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI script only runs from my machine 1

Status
Not open for further replies.

angelo270462

Programmer
Mar 17, 2006
5
GB
Hi guys, another newbie I'm afraid. I have written some scripts (.cgi)to tail log files and display the results in a browser. All works well from my machine, but when i try to run from another machine, the script that runs the "tail -f" command just seems to freeze.
From the user end, they click on a link on a web page - this brings up a dir listing of the log files they can tail - each file is a link - once they click on the file they want, another browser pops up displaying the tailed log file.
I have one script to get to the log files, another to read the log dir and convert the output to links, and another one that tails the selected log file.
Even on other machines, it all works fine until the user clicks the file to be tailed and that's when it freezes, although it works fine all the way on mine.
Any suggestions please.
Thanks
Ang
 
Hi

Hard to guess. No operating system, no web server, no scripting language.

One possible problem is that usually some log files could be read only by privileged users, and is recommended to run web servers as unprivileged user. So the CGI script runned by the web server could not have permission to access that log file.

Feherke.
 
Thanks for your reply.Iam investigating the permissions and will let you know if this works.

Thanks again
Angelo
 
OK, operating system is linux, web server is Apache, scripting language is cgi/perl. Still having problems with this tailing script. It seems to work fine from the command line, but when it goes through a browser it just waits for the tail to finish before displaying to the screen. Of course by definition tail doesn't stop so nothing is pumped to the screen. If I tell it to show me xxx number of lines it's OK because I guess it stops tailing after xxx number of lines then shows me the data.
Is there a way to tail the file in a browser without having to wait for the tail to stop before the data is pumped to the browser?
Thanks
 
Hi

Strange. For now, the first question which comes in my mind, is that [tt]tail[/tt] a real [tt]tail[/tt] command ? Real as opposite to alias, function or symlink to a "cheap" substitute like [tt]busybox[/tt].

Use the [tt]type[/tt] and [tt]file[/tt] commands to find this out :
Code:
[blue]master #[/blue] type tail
tail is /usr/bin/tail
[blue]master #[/blue] file /usr/bin/tail
/usr/bin/tail: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped
From your description the script should be reasonably short. Paste it in.

Feherke.
 
I get this:
/usr/bin/tail: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), not stripped

My first script was :

$query = new CGI;

$file=$query->param('file');

print "Content-type: text/html\n\n";

### this flushes the buffer

$|=1;



### this bit runs the tail command

$cmd = "tail -f $file |";
# $cmd = "tail -100 $file |";


# $cmd = "cat $file |";


$count=0;


open LOG, $cmd or die "Could not open file: $!";

# output some PREformated text
print "<pre>";

while ( <LOG> ){

print "$_";
}

close(LOG);
print "</pre>";

I then read on CPAN that I should not be using the pipe but a module instead(?)

I found a module and stripped it down to the basics but my problems all start once I run the cgi through a browser.

here is the module script.
#!/usr/bin/perl -w -I.
BEGIN { unshift @INC,"./blib/lib/";}
use Tail ;
#use File::Tail 0.91;

use CGI;
$query = new CGI;

### this flushes the buffer
### $|=1;
$|++; #sets $| for STDOUT
$old_handle = select( STDERR ); #change to STDERR
$|++; #sets $| for STDERR
select( $old_handle ); #change back to STDOUT

print "Content-type: text/html\n\n";

$domainAlias=$query->param('DomainAlias');
$file=$query->param('file');

$x= "/path_to_logs_dir/" . $domainAlias . "/logs/" . $file;

print "Testing Output\n" ;
print "$x\n" ;
print "<pre>" ;
$count=0;

$mytail=File::Tail->new(name=>"$x",tail=>20,interval=>1);

## while ($count < 1000) {
## print $count++ . " --->\n" ;
## $nfound=File::Tail::select(undef,undef,undef,5,$mytail);
## print $mytail->{"input"}." (".localtime(time).") ".$mytail->read unless $mytail->predict;

$count=0 ;
while ( defined($line=$mytail->read) )
{
print "$line" ;
## last if $count++ == 200 ;
}
print "</pre>" ;
~


 
Hi

One thing. When you use the CGI module, is better to set the [tt]Content-type[/tt] with that module's things, rather then simply outputing it with [tt]print[/tt].

Sadly, our Apache is out of order and I can not test this problem.

Feherke.
 
sorry i don't understand... better to set the Content-type with that module's things. where would i find this ?
 
Hi

Sorry, I never use the CGI module and I was lazy to look in the man. This is what I want to say :
Code:
print $query->header('text/html');
But probably will not solve anything.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top