-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgarbage_collector.py
More file actions
37 lines (31 loc) · 970 Bytes
/
garbage_collector.py
File metadata and controls
37 lines (31 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import time
import os
import shutil
# run with:
# $nohup python garbage_collector.py </dev/null &>/dev/null &
#delete plots and text files that are over one week old
one_week_ago = time.time() - 604800
# one_minutes_ago = time.time() - 60 #for testing
directory1 = 'web/static/job/'
directory2 = 'sacct_output/'
while True:
try:
os.chdir(directory1)
for somefile in os.listdir('.'):
st=os.stat(somefile)
mtime=st.st_mtime
if mtime < one_week_ago:
# print('remove %s'%somefile)
shutil.rmtree(somefile)
os.chdir('../../../')
os.chdir(directory2)
for somefile in os.listdir('.'):
st=os.stat(somefile)
mtime=st.st_mtime
if mtime < one_week_ago:
# print('remove %s'%somefile)
os.unlink(somefile)
os.chdir('../')
except OSError:
pass
time.sleep(86400) #run daily