由于经常需要到服务器上执行些命令,有些命令懒得敲,就准备写点脚本直接浏览器调用就好了,比如这样:

  

  因为线上有现成的Apache,就直接放它里面了,当然访问安全要设置,我似乎别的随笔里写了安全问题,这里就不写了。

  

vim /etc/httpd/conf/httpd.conf

LoadModule cgid_module modules/mod_cgid.so

AddHandler cgi-script .cgi .py

ScriptAlias /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"
print
print '<html>'
print '<head>'
print '<title>Hello</title>'
print '</head>'
print '<body>' import sys
import subprocess reload(sys)
sys.setdefaultencoding('utf-8')
print subprocess.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,err = result.communicate()
print out.encode('utf-8')
print "<br>"
print err print '</body>'
print '</html>'

  配置好后,用浏览器访问:

  

  因为之前目录不是在www下,而是/var/www/html/cgi-bin/,于是就怀疑suexec:

  

  

  然而改成/var/www/cgi-bin/依然不行,而且suexec也并木有错误日志,看Apache的错误日志:

  

  既然有第二句,那找不到文件应该不是aaa.py找不到,于是我直接执行了一下py脚本:

  

  这就很明显了,这python后面多了点东西,这明显是编码之类的问题,vim进aaa.py,用:set ff看了一下,原来因为这个脚本是在windows上创建的,所以格式是fileformat=dos,用:set ff=unix改一下文件格式然后保存就可以了。

最新文章

  1. 使用Mulesoft建立webservice, simple方式,POJO
  2. 关于通过jq /js 实现验证单选框 复选框是否都有被选中
  3. 171 Excel Sheet Column Number
  4. Mysql Optimization Overview
  5. android开发(49) android 使用 CollapsingToolbarLayout ,可折叠的顶部导航栏
  6. hadooop2.6 job pending research
  7. Unrecognized Windows Sockets error: 0: JVM_Bind
  8. 什么JSONP
  9. Error executing aapt: Return code -1073741819
  10. DWZ (JUI) 教程 DWZ中dialog层的刷新
  11. cygwin下的第一次编程记录
  12. 转 MySQL 用户权限详细汇总
  13. java如何从方法返回多个值
  14. MySQL学习分享--&gt;日期时间类型
  15. Bootstrap下拉菜单
  16. 使用Elasticsearch的动态索引和索引优化
  17. SCOI2019酱油记
  18. 不用Visual Studio,5分钟轻松实现一张报表
  19. Codeforces-542div2
  20. tomcat 虚拟目录

热门文章

  1. 十分钟介绍mobx与react
  2. 分布式系列文章——Paxos算法原理与推导
  3. [版本控制之道] Git 常用的命令总结(欢迎收藏备用)
  4. [APUE]标准IO库(下)
  5. 转:聊聊mavenCenter和JCenter
  6. JQuery(2)
  7. 强强联合,Testin云测&amp;云层天咨众测学院开课了!
  8. 那些年【深入.NET平台和C#编程】
  9. autocomplete的使用
  10. Spark-shell和Spark-Submit的使用