Here's my program import subprocess
print "Content-type:text/html\r\n\r\n" print "File starting to execute" print "<br>" proc = subprocess.Popen(["sudo", "python", "test3.py"], stdout=subprocess.PIPE) output = proc.stdout.read() print "output is %s" %output print "<br>" print "File Executed Awesomely"
Then when I run it in the command line it really works great, like follows->
[root@localhost html]# python test2.py Content-type:text/html File starting to execute <br> output is . Sent 1 packets. <br> File Executed Awesomely [root@localhost html]#
that's perfect the ". Sent 1 packets." is exactly what I would like. However when I run it in the web page, the web page merely has
File starting to execute output is File Executed Awesomely
and so i initially thought it was because I had been doing a problem getting the output however i took in around the port with wireshark (my other program it calls send a packet) also it appears like no packets turns up through the web page call, however it does after i refer to it as around the command line (exactly the same way). Searching inside my apache error_log->
[Wed Jan 18 18:15:11 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Wed Jan 18 18:15:11 2012] [notice] Digest: generating secret for digest authentication ... [Wed Jan 18 18:15:11 2012] [notice] Digest: done [Wed Jan 18 18:15:11 2012] [warn] ./mod_dnssd.c: No services found to register [Wed Jan 18 18:15:11 2012] [notice] Apache/2.2.17 (Unix) DAV/2 configured -- resuming normal operations
any suggestions how I'm able to repair it so my apache cgi-bin script runs exactly the same way because the command line?
EDIT: searching in the log following a couple of calls it will this frequently
[Wed Jan 18 18:22:37 2012] [error] [client 10.117.153.89] : [Wed Jan 18 18:22:37 2012] [error] [client 10.117.153.89] sorry, you must have a tty to run sudo
sorry, you must have a tty to run sudo is paramount. To begin with, letting your apache run sudo is harmful as you would expect, but when you actually actually want to get it done... there is a way, edit
visudo) and locate the
Defaults requiretty part (
NB: Never let apache run anything using sudo, specify what it really must do and absolutely nothing more!
BTW: It might still not work for those who have SELinux enabled or any other LSM module.