# 自搭建了个人博客 有需要交流学习的可以访问

#!/usr/bin/env python

import datetime,os,sys,shutil

log_path = '/alidata/log/nginx/access/'
log_file = 'www.wpython.com.log'

yesterday = (datetime.datetime.now() - datetime.timedelta(days = 1))

try:
os.makedirs(log_path + yesterday.strftime('%Y') + os.sep + \
yesterday.strftime('%m'))

except OSError,e:
print
print e
sys.exit()


shutil.move(log_path + log_file,log_path \
+ yesterday.strftime('%Y') + os.sep \
+ yesterday.strftime('%m') + os.sep \
+ log_file + '_' + yesterday.strftime('%Y%m%d') + '.log')


os.popen("sudo kill -USR1 `cat /alidata/server/nginx/logs/nginx.pid`")