无法使用python3从apache2服务器运行bash脚本?
我有两台Ubuntu电脑,如图所示,它们可以相互ping无法使用python3从apache2服务器运行bash脚本?,python,linux,bash,apache,shell,Python,Linux,Bash,Apache,Shell,我有两台Ubuntu电脑,如图所示,它们可以相互ping PC1<========================>PC2 对于运行bash脚本的代码,发生了两件事: 当我在PC2上本地运行/index.py时,它工作并执行bash脚本文件/test.sh,如图所示,因此也执行/test.sh中提到的top命令 但是 当我通过PC1请求时,apache2崩溃,并在浏览器中给出以下内容: 内部服务器错误 服务器遇到内部错误或配置错误,无法完成您的请求 请通过以下地址与服务器管理员联系
PC1<========================>PC2
对于运行bash脚本的代码,发生了两件事:
/index.py
时,它工作并执行bash脚本文件/test.sh
,如图所示,因此也执行/test.sh
中提到的top
命令
但是[Wed Feb 10 21:40:51.866832 2016] [cgi:error] [pid 9747] [client
127.0.0.1:34506] malformed header from script 'index.py': Bad header:
THIS COMES FROM TEST
[Wed Feb 10 21:40:51.867920 2016] [cgi:error] [pid 9747] [client
127.0.0.1:34506] AH01215: TERM environment variable not set.
Python脚本/index.py
如下所示:
#!/usr/bin/python
import subprocess
subprocess.call("./test.sh", shell=True)
# Turn on debug mode.
import cgitb
cgitb.enable()
# Print necessary headers.
print("Content-Type: text/html\n")
print('<html>')
print('<head>')
print('<title>IoT Based Electric SubStation Monitoring</title>')
print('</head>')
print('<body>')
print('</br>')
print('<marquee><b><h1>IoT Based Electric SubStation Monitoring</h1>
</b></marquee>')
print(' <button type="button">Click here to STOP</button> ')
print('</body>')
print('</html>')
#!/bin/bash
#echo THIS COMES FROM TEST
firefox
#echo STOPPPPPPPPPPPPPPPPPPPP
在写入内容类型头之前,您正在运行bash脚本。反过来做
bash脚本写入与Python脚本相同的stdout,因此Apache服务器看到的第一件事是bash脚本的输出。该输出不是有效的HTTP头,因此会显示错误消息。噢,在bash脚本中运行top可能也不是一个好主意。@SvenMarnach和Rob:感谢您的快速回复,我做了以下更改,但仍然给出了完全相同的错误。1) 删除了subprocess.call(“./test.sh”,shell=True),并在脚本的最后复制了它。2) 从bash脚本中删除了“top”。这次我甚至没有在stdout上重复任何内容,只是在其中包含以下行:#/bin/bash firefox,但仍然存在相同的问题。@MAILERSERVICE:如果错误消息仍然相同(包括字符串“THIS FROM TEST”),但您不再打印此字符串,则您所做的更改不会发送到服务器。@SvenMarnach:Hi,很抱歉再次打扰您,但是我得到的错误和以前一样,除了字符串“THIS FROM TEST”
#!/bin/bash
#echo THIS COMES FROM TEST
firefox
#echo STOPPPPPPPPPPPPPPPPPPPP