大佬教程收集整理的这篇文章主要介绍了Linux系统上面使用python切割nginx日志,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/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$2}‘")
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日志所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。