|
Posted by Phil on 10/31/07 23:45
I cannot figure why this works fine at the command-line of the linux
server, but will not output anything to the browser, and no errors in
the error_log (syslog). The goal here is to have a page to enter a
search term and grep or zgrep pattern matches in the file (will be a
log file). Probably there is a better way to do this using php, but
this is what I was able to come up with using my limited php-
knowledge. Can anyone help me debug this?
<HTML>
<HEAD>
<TITLE>Search Log</TITLE>
</HEAD>
<BODY>
<form action="<?php echo "$_SERVER[PHP_SELF]"; ?>" method="POST">
<input type="text" name="sstr" value="" size="20" maxlength="30"/>
<input type="submit" value="Search!"/>
</form>
<?php
//$test=$_POST['sstr'];
$test="foo";
if (! empty($test))
{
$cmdstr = "grep -i $test <somefile>";
$fp = popen($cmdstr, 'r');
while ($buffer = fread($fp, 8096)) {
echo "<br><hr><pre>";
print($buffer);
echo "</pre>";
flush(); }
pclose($fp);
}
else
{ echo "Please enter a search-term and try again!"; }
?>
</BODY>
</HTML>
Navigation:
[Reply to this message]
|