使用get请求,触发python脚本

[hadoop@iZ25s7cmfyrZ myspider]$ cat mylittle_server.py 
#!/usr/bin/env python
# -*- coding:utf-8 -*-


import cyclone.web
from twisted.internet import reactor
from twisted.python import log
import os, sys
from datetime import datetime

date=datetime.strftime(datetime.now(),"%Y%m%d")

class MainHandler(cyclone.web.RequestHandler):
    def get(self):
        self.write('*********** 说明 ************ <br/> \
                   /python run the scripy  like    +home+hadoop+helloworld.py=20160708 <br/> \
                   /log 显示结果 <br/> \
                   /listdir 线索路径下的文件列表 <br/> \
                   ')


class PythonHandler(cyclone.web.RequestHandler):
    def get(self, pystring):
        realpy=pystring.replace("-","/").replace("="," ")
        #num=len(realpy.split(" "))
        print realpy
        line="/usr/local/bin/Anaconda/bin/python %s" % realpy
        os.system("%s > result_log" % line)
        self.write(line)

class LogHandler(cyclone.web.RequestHandler):
    def get(self):
        fstring=""
        f=open("/data/script/myspider/result_log","r")
        for l_raw in f:
            string=l_raw.strip()+"<br/>"
            print l_raw
            fstring=fstring+string
        self.write(fstring)

class ListDirHandler(cyclone.web.RequestHandler):
    def get(self,path):
        path=path.replace("-","/")
        line=os.listdir(path)
        xstring=""
        for x in line:
            string="<tr> %s <tr/> <br/>" % x
            xstring=xstring+string
        self.write("<table> %s  <table/>" % xstring)

application=cyclone.web.Application([
    (r"/",MainHandler),
    (r"/python/([a-z0-9\.\-\=\_]+)",PythonHandler),
    (r"/log/",LogHandler),
    (r"/listdir/([a-z0-9\.\-\_]+)",ListDirHandler)
    ])


#log.startLogging(open("log.%s" % date,"w"))
log.startLogging(sys.stdout)
reactor.listenTCP(10086,application)
reactor.run()
####################################################

使用get请求 执行服务器指定目录下的脚本

转载于:https://my.oschina.net/lCQ3FC3/blog/815658

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值