- #-*- coding: utf-8 -*-
- #/usr/bin/env python
- import os
- import os.path
- import sys
- ############Setting Area########
- maillog = '/var/log/maillog'
- yumlog = '/var/log/yum.log'
- outputlog = sys.argv[1]
- if os.path.exists(outputlog):
- pass
- else:
- os.system('{} {}'.format('/bin/touch', outputlog))
- print '创建文件'
- contents = []
- try :
- fobj = open(maillog, 'r')
- except IOError, error :
- print ' %s 打开失败:%s' % (maillog,error)
- else :
- for eachline in fobj :
- print eachline
- contents.append(eachline)
- fobj.close()
- try :
- fobj = open(yumlog, 'r')
- except IOError, error :
- print ' %s 打开失败:%s' % (yumlog,error)
- else :
- for eachline in fobj :
- print eachline
- contents.append(eachline)
- fobj.close()
- try:
- theoutputlog_s = open(outputlog,'a')
- except IOError, error :
- print '%s 打开失败:%s' % (theoutputlog_s,error)
- sys.exit()
- theoutputlog_s.writelines(['%s%s' %(eachline, os.linesep) for eachline in contents])
- theoutputlog_s.close()
转载于:
http://blog.csdn.net/killua_hzl/article/details/5573191
阅读(3997) | 评论(0) | 转发(0) |