kristo5747 Posted July 22, 2010 Share Posted July 22, 2010 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. Link to comment https://forums.phpfreaks.com/topic/208569-newbie-question-capture-shell-output-with-exec/ Share on other sites More sharing options...
AbraCadaver Posted July 22, 2010 Share Posted July 22, 2010 You don't want backticks around the command. Just send the command to exec() or shell_exec(). This: $output = `ls -al`; Is the same as this: $output = shell_exec("ls -al"); Link to comment https://forums.phpfreaks.com/topic/208569-newbie-question-capture-shell-output-with-exec/#findComment-1089710 Share on other sites More sharing options...
AbraCadaver Posted July 22, 2010 Share Posted July 22, 2010 Also, $CMD5_output will be an array of lines, even if there is only one line. The return will be the last line. Link to comment https://forums.phpfreaks.com/topic/208569-newbie-question-capture-shell-output-with-exec/#findComment-1089711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.