Jump to content

newbie question: capture shell output with exec()?


kristo5747

Recommended Posts

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.