#!/usr/bin/python import time import os import commands path = [‘/var/log/Nginx/‘,‘access.log‘] (num,NginxpID_str) = commands.getstatusoutput("/usr/bin/ps aux|grep Nginx|grep Nginx|awk ‘/master/{print}‘")NginxpID=int(NginxpID_str.split("\n")[0])yesterday = commands.getoutput(‘date -d "yesterday" +%Y%m%d‘) new_path=‘/var/log/new/‘target="%saccess_%s.log" % (new_path,yesterday)command_main = "cd %s && /bin/mv %s %s && /bin/kill -USR1 %d " % (path[0],path[1],new_path,NginxpID)command_tar = "cd %s && /bin/tar czvf %s.tar.gz %s && rm -f %s%s" % (path[0],target,path[1]) command_del = "/usr/bin/find %s -type f -mtime +11 -exec rm -f {} \;" % (new_path)(status,outtt)=commands.getstatusoutput(command_main)print(status,outtt)if status == 0: print("successs") (tar_status,tar_out)=commands.getstatusoutput(command_tar) if tar_status == 0: print("tar---ok") (del_status,del_out)= commands.getstatusoutput(command_del)else: print("failure")
总结 以上是内存溢出为你收集整理的Linux系统上面使用python切割nginx日志全部内容,希望文章能够帮你解决Linux系统上面使用python切割nginx日志所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)