Due to the frequent need to execute some commands on the server, some commands are too lazy to knock, ready to write a script direct browser calls, such as:
Because there is a ready-made Apache on the line, just put it inside, of course, access security to set, I seem to write the other essays on security issues, here do not write.
Vim/etc/httpd/conf/httpd.confloadmodule cgid_module modules/mod_cgid.soaddhandler cgi-script. CGI. PyScriptAlias/ cgi-bin/"/var/www/cgi-bin/" <directory "/var/www/cgi-bin" > allowoverride None Options +execcgi Order Allow,deny allow from all# Options Indexes followsymlinks multiviews +execcgi# allowoverride none# Options none# Order allow,deny# allow from all</directory>
Chmod-r 755 /var/www/cgi-bin/
#!/usr/bin/python#-*-coding:utf-8-*-Print "content-type:text/html"PrintPrint ''Print ''Print '<title>Hello</title>'Print ''Print '<body>'ImportSYSImportsubprocessreload (SYS) sys.setdefaultencoding ('GB2312')PrintSubprocess.call (["/bin/grep","Exception","/var/log/error/20160706.log"])Print "<br>"RESULT1= subprocess. Popen (["/bin/grep Exception/var/log/error/20160706.log"], Shell=true, stdout=subprocess. PIPE) Result= subprocess. Popen (["grep"," not"],stdin=result1.stdout, stdout=subprocess. PIPE) out=result.communicate ()Print outPrint '</body>'Print ''
When configured, use the browser to access:
Because before the directory is not under the WWW, but/var/www/html/cgi-bin/, so suspicion suexec:
however , the change to/var/www/cgi-bin/still does not, and suEXEC also wood has error log , see Apache error log:
Since there is a second sentence, that can not find the file should not be aaa.py found, so I directly executed the PY script:
This is obvious, this python behind a little more things, this is obviously coding problems, vim into the aaa.py, with: Set FF looked at, originally because this script is created on Windows, so the format is Fileformat=dos, with: Set ff= UNIX to change the file format and then save it.
Apache executes Python script