Python切割nginx日志
前面写过bash shell对nginx日志的切割,现在用python进行其操作。
#!/usr/bin/python#-*-coding:UTF-8-*-'''Created on 2011-11-17切割Nginx的日志文件,重新生成一个log日志,nginx的进程号不变动@author: jimingsong'''import timeimport ospath = ['/usr/local/nginx/logs/', 'nginx.pid','access.log']str = time.strftime('%Y%m%d%H%M%S')tar_conn1 = "cd %s && /bin/mv %s %s && /bin/kill -USR1 `cat %s`" % (path[0],path[2],str,path[1])tar_conn = "cd %s && /bin/tar czvf %s %s" % (path[0],target,path[2])if os.system(tar_conn1) == 0: print '切割成功', strelse: print 'Error,操作失败'