[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [cobalt-users] Re: Real time log monitoring script
- Subject: RE: [cobalt-users] Re: Real time log monitoring script
- From: BSmith@xxxxxxxxxxx
- Date: Wed Sep 24 08:25:01 2003
- List-id: Mailing list for users to share thoughts on Sun Cobalt products. <cobalt-users.list.cobalt.com>
Here is a Start in PHP ... just need to change the file to 'read' for the
world though (limitation of PHP, as it runs as 'httpd'). If you change
"$filename", you can watch any log file, via the web, real time ... Easy to
change around to make it do whatever you want it to do.
<?php
ini_set("max_execution_time",3000000);
$filename = "/var/log/maillog";
$file_size = filesize($filename);
$fh = fopen($filename, 'r');
$myOutput = fread($fh, $file_size);
$myOutput = str_replace("\n", "<br>\n", $myOutput);
# Uncomment this line, if you want to see previous
# output as well.
#print $myOutput;
# I used $c for debugging ... just keeps it 1=1, for
# a continuous loop.
$c = 1;
while ( $c == 1 )
{
clearstatcache();
$tmpSize = filesize($filename);
if ( $tmpSize <> $file_size )
{
print "ok";
$readBytes = $tmpSize - $file_size;
$file_size = $tmpSize;
$myOutput = fread($fh, $readBytes);
print $myOutput;
echo str_pad(" ", 256) . "<br>";
flush();
$c=1;
}
}
?>
That will print like a "tail -f" ... Developed by ME. It works too.