1:安装web.py

参考:http://webpy.org/install.zh-cn


下载web.py

# wget http://webpy.org/static/web.py-0.33.tar.gz

 

安装web.py

 

# tar zxvf web.py-0.33.tar.gz
# cd web.py-0.33

 

使所有的web程序可以访问

 

# python setup.py install

 

OK,安装完毕,关于web.py请参考http://webpy.org/install.zh-cn

 

2:编写Python脚本,通过web.py的小web服务程序实现动态访问

# mkdir python 
# cd python
# vi logview.py
import web
import os
urls = (
  '/', 'index'
)  
class index:
  def GET(self):
    command = 'tail -fn100 /opt/tomcat/logs/catalina.out'
    textlist = os.popen(command).readlines()
    result = '<h1>Last 100 lines log</h1>'
    for line in textlist:
           result = '%s\n%s'%(result,line) 
    return result
if __name__ == "__main__": 
  app = web.application(urls, globals())
  app.run()


 ###command定义文件,根据实际情况修改查看多少行,或tomcat的日志位置

 

3:启动web.py服务,指定端口

 

# nohup python  /root/python/logview.py 9090 &

 

###端口9090可以随意指定,只要没被占用,默认为8080


4:通过web访问

http://127.0.0.1:9090