Executing system command in php, differs in using broswer and in using command line
Posted
by Amit
on Stack Overflow
See other posts from Stack Overflow
or by Amit
Published on 2010-06-05T13:08:44Z
Indexed on
2010/06/05
13:12 UTC
Read the original article
Hit count: 236
Hi,
I have to execute a Linux "more" command in php from a particular offset, format the result and display the result in Browser.
My Code for the above is :
<html>
<head>
<META HTTP-EQUIV=REFRESH CONTENT=10>
<META HTTP-EQUIV=PRAGMA CONTENT=NO-CACHE>
<title>Runtime Access log</title>
</head>
<body>
<?php
$moreCommand = "more +3693 /var/log/apache2/access_log | grep -v -e '.jpg' -e '.jpeg' -e '.css' -e '.js' -e '.bmp' -e '.ico'| wc -l";
exec($moreCommand, $accessDisplay);
echo "<br/>No of lines are : $accessDisplay[0] <br/>";
?>
The output at the browser is :: No of lines are : 3428 (This is wrong)
While executing the same command using command line gives a different output. My code snippet for the same is :
<?php
$moreCommand = "more +3693 /var/log/apache2/access_log | grep -v -e '.jpg' -e '.jpeg' -e '.css' -e '.js' -e '.bmp' -e '.ico'| wc -l";
exec($moreCommand, $accessDisplay);
echo "No of lines are : $accessDisplay[0] \n";
?>
The output at the command line is :: No of lines are : 279 (This is correct)
While executing the same command directly in command line, gives me output as 279.
I am unable to understand why the output of the same command is wrong in the browser. Its actually giving the word count of lines, ignoring the offset parameter.
Please help !!
Thanks, Amit
© Stack Overflow or respective owner