Using PHP I would like to be able to list root’s crontab.
I am able to run the following command as the Apache user from the command line and get the desired result:
sudo crontab -l
however, in my PHP I have the following command which does not work and returns an empty set:
exec('sudo crontab -l', $out);
print_r($out);
Is it environmental? Or permissions?
I have also tried shell_exec() system() and passthru()
Also, note that I have disabled SELinux and added Apache to the sudoers file so that it does not need to be prompted for a password.
Solved: Even though I had set error reporting on, you must redirect the output of the command like so:
After setting this, I found the following error:
Following research of the issue, the resolution is to edit the sudoers file and comment out: #Default requiretty.
http://www.zimbra.com/forums/installation/10553-solved-sudo-sorry-you-must-have-tty-run-sudo.html
I apologize as I got further into this issue, it became less of a PHP issue and more of unix system question.