The egrep
command isn't working, because you're using single quotes as a string constant delimiter: 'egreep -w'
<==> 2012-09-01|974'
<==> /home/myquery_test/log/push.log'
<==
Just use double quotes in the string, or as string delimiters OR escape the quotes.
shell_exec('egrep -w \'2012-09-01|974\' /home/myquery_test/log/push.log');
shell_exec('egrep -w "2012-09-01|974" /home/myquery_test/log/push.log');
shell_exec("egrep -w '2012-09-01|974' /home/myquery_test/log/push.log");
And, to avoid not getting the warnings and errors that would have brought this issue to light when testing, set your ini to E_STRICT|E_ALL
, and fix the warnings, rather then ignoring them. [teasingly: after you're done with that, you might want to consider accepting some answers]I see you've accepted a lot while I was typing this post up :)
Using variables in your command:
$output = shell_exec("tail -f | egrep '$number.*$date' /var/www/myquery_test/log/push.log");
$output = shell_exec('tail -f | egrep "'.$number.'.*'.$date.'" /var/www/myquery_test/log/push.log');
$output = shell_exec("tail -f | egrep \"$number.*$date\" /var/www/myquery_test/log/push.log");