I have a perl script that works fine with sudo and parses some logfiles at /var/log/ in Ubuntu 14. I want to show the program output on a webpage. My webpage code is very simple:
<html><body> <h1>Under construction</h1> <?php exec ("perl /usr/local/bin/pflogsumm -d yesterday --smtpd_stats /var/log/mail/mail.log > parsed_mail_log.txt"); echo "<pre><p style='font-family:monospace;'>".nl2br(file_get_contents("parsed_mail_log.txt"))."</p></pre>"; ?> </body></html>
Without sudo, www-data (I guess that is the user when running the script) does not have permissions to access /var/log/mail/mail.log and does not count what I want. It outputs stuff, but only zeroes in place of the numbers I wanted to check.
My question is: what should be the "good" way of doing this?
Putting www-data in the root group so that it can read the log does not seem right.
Maybe I could invoke a script with sudo, inside such script invoke
sudo perl /usr/local/bin/pflogsumm -d yesterday...
And add the previous script to visudo so that www-data could run it with sudo without asking for authentication. Again, it seems it is not the "good" or the "right" way of doing it...