Delete the full Python script for more than 1 years of data:
VI aa.py
#!/usr/bin/python
Import OS
Import datetime
Import Shutil
Dir= "/AA"
now = Datetime.datetime.now ()
Delta = Datetime.timedelta (days=365)
Os.remove ("/log/110hudrm/gmss.txt")
Os.mknod ("/log/110hudrm/gmss.txt")
Os.chdir (dir)
str1 = "_w"
For Root,dirs,files in Os.walk (dir):
For F in dirs:
if f = = "Ima":
Mtime = Datetime.datetime.fromtimestamp (Os.path.getmtime (Os.path.join (root,f)))
If Mtime < (Now-delta):
b = Os.path.dirname (Os.path.join (root,f))
If str1 in B:
D = Os.path.dirname (Os.path.join (root,f))
p = open ('/log/110hudrm/gmss.txt ', ' a ')
P.write (d+ "\ n")
P.close ()
Size = 0
c = open ('/log/110hudrm/gmss.txt ', ' R ')
For I in C.readlines ():
For Root,dirs,files in Os.walk (I.strip ()):
Size + = SUM (os.path.getsize (Os.path.join (ROOT,FI)) for fi in Files)
Si = size/1024/1024/1024
E = open ('/log/110hudrm/gmss2.txt ', ' W ')
E.write (str (SI) + ' G ')
E.close ()
c = open ('/log/110hudrm/gmss.txt ', ' R ')
For I in C.readlines ():
Shutil.rmtree (I.strip ())
Os.system ('/usr/bin/mail-s ' host1 (10.0.0.2) AA Delete (over 1 years) Size at date +%Y-%m-%d "[email protected] </log/110hudrm/g Mss2.txt ')
: Wq
Python aa.py
Delete data complete Python script for more than 1 years