Forum Moderators: coopster

Message Too Old, No Replies

Not working!? Capture shell output with exec()

         

kristo5747

6:03 pm on Jul 22, 2010 (gmt 0)

10+ Year Member



Greetings!

I have the task to parse log files for several web servers and output a report in a web page (the later part's easy).

My problem: the log files are huge (> 1GB) so using any of the PCRE functions is not doable. `Out of memory error` will happen.

So I need to rely on the OS to do the bulk of the work. From the command line, I can run this grep statement to look for a specific URL:

grep \"basket.htm?skuId=10010\" weblogfile | grep --only-matching '\"GET[^\"\-]*\"' | sort -u | wc -l


if a match is found for that Sku, I simply count the number of occurrences in the log file (that's how I build the report).

If no match is found, the grep command returns 0 (as expected) and I am supposed to output "N/A" in my report. I started reading up about exec() this morning but I can't get it to capture the grep command's output


...
/$CMD5 = "grep \"static_tvapp.htm?widgetId=".$widgetID[$i]."\" tmpfile | grep -oa '\"GET[^\"\-]*\"' | sort -u | wc -l";
@exec($CMD5, $CMD5_output, $retval);
if ($CMD5_output != "0") {
exec('echo N/A' >> Baskets.csv');
} else {
...do something else...
}


It simply does not work. What am I missing? Can someone please help?

Thank you.

Al.

jatar_k

7:38 pm on Jul 22, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



have you tried passthru instead?

[php.net...]

also be sure that your php.ini doesn't disallow that function in 'disable_functions'