1 |
tboccali |
1.1 |
#!/bin/tcsh
|
2 |
|
|
|
3 |
|
|
#
|
4 |
|
|
# so: try and have files lasting at least $retention_time;
|
5 |
|
|
#
|
6 |
|
|
#
|
7 |
|
|
# dquota is the quota of the area
|
8 |
|
|
# minfree must be the minimum free area to complete current operations
|
9 |
|
|
#
|
10 |
|
|
|
11 |
|
|
# if disk used more than $maxdisk, delete the oldest ones respecting the previous requirement
|
12 |
|
|
# if disk used more than $maxdisk, delete the oldest ones without respecting the previous requirement, but then send a WARNING
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
set verb=1
|
16 |
|
|
|
17 |
|
|
set AREA=/afs/cern.ch/cms/CAF/CMSCOMM/COMM_GLOBAL/EventDisplay/RootFileTempStorageArea
|
18 |
|
|
|
19 |
|
|
#
|
20 |
|
|
# in hours
|
21 |
|
|
#
|
22 |
|
|
|
23 |
|
|
set retention_time=100
|
24 |
|
|
|
25 |
|
|
#
|
26 |
|
|
# disk quota (in kB)
|
27 |
|
|
#
|
28 |
|
|
|
29 |
|
|
# this is 5 GB
|
30 |
tboccali |
1.2 |
set dquota=10000000
|
31 |
tboccali |
1.1 |
|
32 |
|
|
#
|
33 |
|
|
# minfree (in kB)
|
34 |
|
|
#
|
35 |
|
|
|
36 |
|
|
# this is 1 GB
|
37 |
tboccali |
1.3 |
set minfree=3000000
|
38 |
tboccali |
1.1 |
|
39 |
|
|
@ maxdisk= $dquota - $minfree
|
40 |
|
|
|
41 |
|
|
if ($verb) then
|
42 |
|
|
echo Setting maxdisk to $maxdisk
|
43 |
|
|
endif
|
44 |
|
|
#
|
45 |
|
|
# get disk used
|
46 |
|
|
#
|
47 |
|
|
cd $AREA
|
48 |
|
|
set used=`du -s |awk '{print $1}'`
|
49 |
|
|
|
50 |
|
|
if ($verb) then
|
51 |
|
|
echo Used disk is $used
|
52 |
|
|
endif
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
if ($used < $maxdisk) then
|
56 |
|
|
#
|
57 |
|
|
# nothing to do
|
58 |
|
|
#
|
59 |
|
|
if ($verb) then
|
60 |
|
|
echo Exit with code 0
|
61 |
|
|
endif
|
62 |
|
|
|
63 |
|
|
exit 0
|
64 |
|
|
endif
|
65 |
|
|
|
66 |
|
|
# first test - see if you can clean applying retention time
|
67 |
|
|
if ($used > $maxdisk) then
|
68 |
|
|
if ($verb) then
|
69 |
|
|
echo Running tmpwatch
|
70 |
|
|
endif
|
71 |
|
|
/usr/sbin/tmpwatch --verbose -d --atime $retention_time .
|
72 |
|
|
endif
|
73 |
|
|
#
|
74 |
|
|
# now look whether situation is good
|
75 |
|
|
#
|
76 |
|
|
set newused=`du -s |awk '{print $1}'`
|
77 |
|
|
|
78 |
|
|
if ($verb) then
|
79 |
|
|
echo Now used is $newused
|
80 |
|
|
endif
|
81 |
|
|
|
82 |
|
|
if ($newused < $maxdisk) then
|
83 |
|
|
#
|
84 |
|
|
# I am happy, I bail out
|
85 |
|
|
# exit 2 = i had to delete, but just stuff I could delete
|
86 |
|
|
exit 2
|
87 |
|
|
endif
|
88 |
|
|
|
89 |
|
|
#
|
90 |
|
|
# else, delete files in order of age, one by one
|
91 |
|
|
#
|
92 |
|
|
while ($newused > $maxdisk)
|
93 |
|
|
#
|
94 |
|
|
# find the oldest file
|
95 |
tboccali |
1.3 |
set file=`ls -t1 *root|tail -1`
|
96 |
tboccali |
1.1 |
|
97 |
|
|
if ($verb) then
|
98 |
|
|
echo Deleting $file
|
99 |
|
|
endif
|
100 |
|
|
rm -f $file
|
101 |
|
|
#calculate new disk free
|
102 |
|
|
set newused=`du -s |awk '{print $1}'`
|
103 |
|
|
if ($verb) then
|
104 |
|
|
echo Now free is $newused
|
105 |
|
|
endif
|
106 |
|
|
#
|
107 |
|
|
end
|
108 |
|
|
|
109 |
|
|
#exit three means I had to delete stuff not expired
|
110 |
|
|
exit 3
|
111 |
|
|
|
112 |
|
|
#
|