Home > Archive > PHP Language > February 2005 > CAT / GREP / Tail
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hi..
can anyone point to a site that can offer advice on creating a web
page that will allow me to view a live log file and the run cat, grep,
tail from a web page on that file !!
Thanks
| |
| Colin McKinnon 2005-02-23, 3:55 pm |
| TomT wrote:
> Hi..
>
> can anyone point to a site that can offer advice on creating a web
> page that will allow me to view a live log file and the run cat, grep,
> tail from a web page on that file !!
>
> Thanks
HTTP is a stateless protocol so you can only get a 'snapshot' of the file.
You can use javscript to keep updating that snapshot or deliver another
program (maybe a java applet) which uses a different protocol to get the
data.
HTH
C.
| |
|
| any pointers of where to look for some info ??
Thanks
On Wed, 23 Feb 2005 15:33:23 +0000, Colin McKinnon
<colin.deletethis@andthis.mms3.com> wrote:
>TomT wrote:
>
>
>HTTP is a stateless protocol so you can only get a 'snapshot' of the file.
>You can use javscript to keep updating that snapshot or deliver another
>program (maybe a java applet) which uses a different protocol to get the
>data.
>
>HTH
>
>C.
| |
| Dave Patton 2005-02-23, 3:55 pm |
| TomT <tomt@adslweb.co.uk> wrote in
news:94mo11lpnsi0kv3enpqmsjdavm5dqsroj3@
4ax.com:
> Hi..
>
> can anyone point to a site that can offer advice on creating a web
> page that will allow me to view a live log file and the run cat, grep,
> tail from a web page on that file !!
http://www.php.net/manual/en/function.exec.php
For example:
$tailval = 20;
$logroot = '/var/logs';
$file = 'access_log';
$command = "tail -{$tailval} {$log_root}/$file";
print("<pre>");
unset($output);
$result = exec( $command, $output, $retval );
print("{$command}<br>");
print("Status: {$retval}<br>");
foreach($output as $outputline)
{
print("$outputline<br>");
}
print("</pre>");
--
Dave Patton
Canadian Coordinator, Degree Confluence Project
http://www.confluence.org/
My website: http://members.shaw.ca/davepatton/
| |
| Senator Jay Billington Bulworth 2005-02-27, 3:56 pm |
| Colin McKinnon <colin.deletethis@andthis.mms3.com> wrote in
news:cvi7nk$crr$1$830fa79d@news.demon.co.uk:
> TomT wrote:
>
a web[color=darkred]
cat,[color=darkred]
>
> HTTP is a stateless protocol so you can only get a 'snapshot'
of the
> file. You can use javscript to keep updating that snapshot or
deliver
> another program (maybe a java applet) which uses a different
protocol
> to get the data.
>
> HTH
>
> C.
It's possible to emulate the function of "tail -f" via PHP. It
isn't likely to work in safe mode, so shared hosting
environments might not be a great place to run it, but here's
some "tail -f" code. The larger you set $lines and the smaller
you set $sleep, the more strain this will put on a server.
<?php
set_time_limit(60);
$file = '/var/log/httpd/access_log';
$sleep = 1;
$lines = 100;
echo '<pre>';
$command = 'tail -' . (int)$lines . " \"$file\"";
$newtail = $oldtail = array();
while(1){
$tail = '';
$fp = popen($command, 'r') or die("Unable to run command:
$command");
while(!feof($fp)){
$tail .= fread($fp, 4096);
if(feof($fp)){
break;
}
}
pclose($fp);
$newtail = explode("\n", trim(rtrim($tail)));
for($i=0; $i<count($newtail); $i++){
if(in_array($newtail[$i], $oldtail)){
continue;
}
echo "$newtail[$i]\n";
}
$oldtail = $newtail;
flush();
sleep($sleep);
}
?>
hth
--
Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.arg');
--------------------------|---------------------------------
<http://www.phplabs.com/> | PHP scripts, webmaster resources
|
|
|
|
|