Skip to content

Instantly share code, notes, and snippets.

@hideshi
Created December 8, 2013 13:05
Show Gist options
  • Save hideshi/7857158 to your computer and use it in GitHub Desktop.
Save hideshi/7857158 to your computer and use it in GitHub Desktop.
Log rotation script. This script would be called by cron at fixed intervals.
from os.path import getsize
from os import rename
from datetime import datetime
srcnames = ['./logfile1', './logfile2']
kb = 1024
mb = kb * 1024
def log_rotate():
for srcname in srcnames:
size = getsize(srcname)
if size > 10 * mb :
dstname = srcname + "." + datetime.now().strftime('%Y%m%d%H%M%S')
rename(srcname, dstname)
if __name__ == '__main__':
log_rotate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment