I have a bash script to extract information from exim_mainlog. When the bash script is run from a putty command line (logged in as root), the extracted data is properly written to an output file. However, when the bash script is invoked from a PHP webpage, the grep results are written to the output file, but the exigrep results are not. The PHP webpage lives in a cPanel account.
It does not seem to be a permissions issue because the grep extract from the exim_mainlog, is properly written to the output file while the exigrep extracts are not.
Here is my PHP:
<?php $output=shell_exec("sh /home/account/public_html/cgi-bin/Log.sh"); ?>
Here is the bash script with 3 attempts to extract data. All three work when the script is invoked by the command line "sh /home/account/public_html/cgi-bin/Log.sh", but only the grep results are written (and the exigrep results are not written) when the bash script is invoked by the PHP script:
#!/bin/bash # grep attempt consistently writes data to the temp.log file echo "grep" > /home/account/public_html/cgi-bin/temp.log # just a label so the source of the results is known grep "email address" /var/log/exim_mainlog |\ sed -r -e 's/[[<>]/"&"/g' >> /home/account/public_html/cgi-bin/temp.log # exigrep attempts do not work when invoked with the PHP above echo "exigrep" >> /home/account/public_html/cgi-bin/temp.log # just a label so the file location where the exigrep results should be is known exigrep "email address" /var/log/exim_mainlog |\ sed -r -e 's/[[<>]/"&"/g' >> /home/account/public_html/cgi-bin/temp.log exigrep --no-pager "email address" /var/log/exim_mainlog |\ sed -r -e 's/[[<>]/"&"/g' >> /home/account/public_html/cgi-bin/temp.log
I also tried "exec" instead of "shell_exec" with the same results.
Based on Fox comment below, I looked to see if the permissions for exigrep were different than that of grep; they were the same (others can execute).
exigrep
?./
? not/
? my thought was perhapsexigrep
might not be in thePATH
when run by php