apache cgi python
修改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
本文出自 “expect批量同步数据” 博客,请务必保留此出处http://4249964.blog.51cto.com/4239964/1441496
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。