怎么用python 日志拉取游戏日志

【Python】用Python获取命令行输出
折腾了好久才搞定,记录一下。我是用的是windows系统,python
' #可以直接在命令行中执行的命令
os.popen(command) #执行该命令
r.readlines() &#读取命令行的输出到一个list
for line in
info: &#按行遍历
& & line =
line.strip('\r\n')
------------------------------------------------------//-------------------------------------------
python中的os.system()和os.popen()区别
python调用Shell脚本或者是调用系统命令,有两种方法:os.system(cmd)或os.popen(cmd),前者返回值是脚本的退出状态码,后者的返回值是脚本执行过程中的输出内容。实际使用时视需求情况而选择。
参考:http://www.conxz.net/blog//sloppy-python-snippets-to-capture-command-output/
/songmingming/p/3142837.html
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。Python 拉取日志文件paramiko
时间: 01:53:16
&&&& 阅读:485
&&&& 评论:
&&&& 收藏:0
标签:paramiko的另一篇博文:场景:在游戏行业的集群中,日志分析或许是必不可少的,那么为了更方便的管理日志,就是统一存放日志,然后入库数据库#!/usr/bin/env&python
#coding:utf8
from&multiprocessing&import&Process
from&datetime&import&*
import&paramiko
import&string
import&sys
Hostinfo&=&{
"192.168.1.100"&:&{
"s200"&:&"/home/platform/work/business/s200/deploy/container/statistics/log/",
&&&& "s202":&"/home/platform/work/business/s202/deploy/container/statistics/log/"
"192.168.1.102"&:&{
"s201"&:&"/home/platform/work/business/s201/deploy/container/statistics/log/",
"s203"&:&"/home/platform/work/business/s203/deploy/container/statistics/log/"
"192.168.1.103"&:&&{
"s000"&:&"/root/project/business/deploy/container/statistics/log/",
&&&& "s100"&:&"/home/platform/work/business/s100/deploy/container/statistics/log/",
"s101"&:&"/home/platform/work/business/s101/deploy/container/statistics/log/"
"192.168.1.104"&:&{
"s001"&:&"/home/game/business_test/deploy/container/statistics/log/"
def&sftpGet(ip,subdir,logdir,remotefile):
&&&&Username,&Port,&Password&=&‘root‘,&22,&‘password‘
&&&&cmd&=&‘cd&%s&&&&rm&-rf&*.tar.gz&&&&ls&%s&&&&[&$?&-eq&0&]&&&&tar&zcf&%s.tar.gz&%s&||&exit&1‘&%&(logdir,&remotefile,&remotefile,&remotefile)
&&&&s&=&paramiko.SSHClient()
&&&&s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
&&&&s.connect(hostname=ip,&port=Port,&username=Username,&password=Password)
&&&&s.exec_command(cmd)
&&&&s&=&paramiko.Transport((ip,Port))
&&&&s.connect(username=Username,password=Password)
&&&&sftp&=&paramiko.SFTPClient.from_transport(s)
&&&&formatfile&=&string.join([ip,subdir,remotefile],sep="_")
&&&&localfile&=&formatfile&+&‘.tar.gz‘
&&&&localDir&=&os.path.abspath(os.path.join(os.path.dirname(__file__),&"collect"))
&&&&if&not&os.path.exists(localDir):
&&&&&&&&os.makedirs(localDir)
&&&&local_abspath_file&=&os.path.join(localDir,localfile)
remote_tarfile&=&remotefile&+&‘.tar.gz‘
&&&&&&&&remote_abspath_file&=&os.path.join(logdir,remote_tarfile)
&&&&&&&&sftp.get(remote_abspath_file,local_abspath_file)
&&&&&&&&s.close()
&&&&except:
print&‘‘,&
def&ipProcess():
&&&&yesterday&=&datetime.now()&+&timedelta(days=-1)
&&&&now&=&yesterday.strftime("%Y%m%d")
&&&&remotefile&=&string.join(["action",now,"log"],sep=".")
&&&&for&key,&value&in&Hostinfo.items():
for&subdir,&logdir&in&value.items():
&&&&sftpGet(ip,subdir,logdir,remotefile)
&&&&&&&&&&&&#p&=&Process(target=sftpGet,args=(ip,subdir,logdir,remotefile))
&&&&#p.start()
&&&&#p.join()
if&__name__&==&"__main__":
&&&&ipProcess()本文出自 “” 博客,请务必保留此出处标签:原文:http://./2088
教程昨日排行
&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!

我要回帖

更多关于 python 日志 的文章

 

随机推荐