Apache executes Python script

Source: Internet
Author: User
Tags apache error log python script

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.