|
#!/bin/env python
import sys
import os
import commands
import datetime,time
#get mongo pid
mongo_pid = commands.getoutput("/sbin/pidof mongod")
print mongo_pid
#send Sig to mongo
if mongo_pid != '':
cmd = "/bin/kill -USR1 %s" %(mongo_pid)
print cmd
mongo_rotate = commands.getoutput(cmd)
else:
print "mongod is not running..."
#clean log which > 7 days
str_now = time.strftime("%Y-%m-%d")
dat_now = time.strptime(str_now,"%Y-%m-%d")
array_dat_now = datetime.datetime(dat_now[0],dat_now[1],dat_now[2])
lns = commands.getoutput("/bin/ls --full-time /var/log/mongodb/|awk '{print $6, $9}'")
for ln in lns.split('\n'):
ws = ln.split()
if len(ws) != 2:
continue
ws1 = time.strptime(ws[0],"%Y-%m-%d")
ws2 = datetime.datetime(ws1[0],ws1[1],ws1[2])
if (array_dat_now - ws2).days > 7:
v_del = commands.getoutput("/bin/rm -rf /var/log/mongodb//%s" % (ws[1]))
|
|
|