前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >apache cgi python

apache cgi python

作者头像
py3study
发布2020-01-13 12:56:06
9860
发布2020-01-13 12:56:06
举报
文章被收录于专栏:python3python3python3

修改apache配置文件如下

<Directory "/usr/local/sae/httpd//htdocs/cgi-bin">

    AllowOverride None

    Options ExecCGI

    Order allow,deny

    Allow from all

</Directory>

     AddType text/html .htm .html .py

     AddHandler cgi-script .cgi .py

编写hello_get.py,放在/usr/local/sae/httpd/htdocs/cgi-bin/目录下,赋予权限chmod a+x hello_get.py

代码:

#!/usr/bin/python

import cgi

import os

import time

import cStringIO

import json

form = cgi.FieldStorage()

ip=form.getvalue('ip')

head_lines=form.getvalue('head_lines')

print "Content-type: text/html\n\n"

address_dict={'10.13.144.':'bx','10.73.26.':'tc','10.75.7.':'yf','10.67.15.':'yq'}

a=ip.split(".")

b=a[0:3]

d=a[-1]

e=".".join(b)

c=e+"."

address_1=address_dict[c]

f=str(d)

g=address_1+f

time_day=time.strftime('%Y-%m-%d')

h=os.popen('grep -R %s /data1/saelog/%s/error/'%(g,time_day))

head_list=[]

sum=0

dict={}

if head_lines:

        for i in h:

                j=i.split(":")[1:]

                head_list.append(j)

        for kk in head_list:

                dict[sum]=head_list[sum]

                sum+=1

                if sum == int(head_lines):

                        break;

        print dict

        dict_json=json.dumps(dict)

        print dict_json

else:

        for i in h:

                j=i.split(":")[1:]

                head_list.append(j)

        for kk in head_list:

                dict[sum]=head_list[sum]

                sum+=1

        dict_json=json.dumps(dict)

        print dict_json

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-08-08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档