-   Programming (
-   -   PHP: what's wrong with this line (shell_exec, find, xargs, grep)? (

J_Szucs 11-19-2003 12:24 AM

PHP: what's wrong with this line (shell_exec, find, xargs, grep)?
The commands below only return any output, if the total length of filenames returned by the find command and piped to the grep command is less then cca. 50kB:

$strCmd = 'find ' . $mappa . ' -name "' . $strFilename . '" -type f -print | xargs grep -l -i -E "' . $strText . '"' ;
$strList = shell_exec($strCmd)


Sorry, it turned out that the problem is caused by a subsequent command, which is:
$strCmd1 = 'echo ' . $strList . ' | xargs grep -l -i -E "' . strText1 . '"'

The problem is, I think, that $strList may contain too long data to be passed to echo as argument.

But, if I cannot use echo, how to pass the value of $strList to grep???

Bluesuperman 11-19-2003 02:05 AM

Try this instead:

exec("/usr/local/bin/sar | grep Average | gawk '{print $3 \"\\n\" $4 \"\\n\" $5 \"\\n\" $7}'",$sarout);

$user = $sarout[0];
$nice = $sarout[1];
$syst = $sarout[2];
$idle = $sarout[3];

J_Szucs 11-19-2003 10:03 AM

> /usr/local/bin/sar

My system does not seem to have this tool. What is it for?

In the meantime I could solve the problem by saving the output of every single search in a temporary file, and using that as the input of the next search.
I think, however, that this could be faster if no disk access was necessary. Though - who knows if there is any...

Bluesuperman 11-19-2003 08:44 PM

the "usr/local/bin/sar" is just the command I am running, you can replace it with what ever command you want.

Check out

Is it a system stats utility -- provides great information.


All times are GMT -5. The time now is 11:58 AM.