ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VisualizationOperations/scripts/clearTemporaryArea.csh
Revision: 1.7
Committed: Fri Mar 19 08:35:49 2010 UTC (15 years, 1 month ago) by tboccali
Content type: application/x-csh
Branch: MAIN
CVS Tags: V19032010-2, V19032010
Changes since 1.6: +2 -2 lines
Log Message:
allow for more space

File Contents

# User Rev Content
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 malgeri 1.6 if ($#argv != 1) then
14     echo "Usage: $0 <directory>"
15     exit 1
16     endif
17 tboccali 1.1
18     set verb=1
19    
20 tboccali 1.5 set AREA=$1
21 tboccali 1.1
22     #
23     # in hours
24     #
25    
26 tboccali 1.7 set retention_time=20
27 tboccali 1.1
28     #
29     # disk quota (in kB)
30     #
31    
32     # this is 5 GB
33 tboccali 1.2 set dquota=10000000
34 tboccali 1.1
35     #
36     # minfree (in kB)
37     #
38    
39     # this is 1 GB
40 tboccali 1.7 set minfree=6000000
41 tboccali 1.1
42     @ maxdisk= $dquota - $minfree
43    
44     if ($verb) then
45     echo Setting maxdisk to $maxdisk
46     endif
47     #
48     # get disk used
49     #
50     cd $AREA
51     set used=`du -s |awk '{print $1}'`
52    
53     if ($verb) then
54     echo Used disk is $used
55     endif
56    
57    
58     if ($used < $maxdisk) then
59     #
60     # nothing to do
61     #
62     if ($verb) then
63     echo Exit with code 0
64     endif
65    
66     exit 0
67     endif
68    
69     # first test - see if you can clean applying retention time
70     if ($used > $maxdisk) then
71     if ($verb) then
72     echo Running tmpwatch
73     endif
74     /usr/sbin/tmpwatch --verbose -d --atime $retention_time .
75     endif
76     #
77     # now look whether situation is good
78     #
79     set newused=`du -s |awk '{print $1}'`
80    
81     if ($verb) then
82     echo Now used is $newused
83     endif
84    
85     if ($newused < $maxdisk) then
86     #
87     # I am happy, I bail out
88     # exit 2 = i had to delete, but just stuff I could delete
89     exit 2
90     endif
91    
92     #
93     # else, delete files in order of age, one by one
94     #
95     while ($newused > $maxdisk)
96     #
97     # find the oldest file
98 tboccali 1.3 set file=`ls -t1 *root|tail -1`
99 tboccali 1.1
100     if ($verb) then
101     echo Deleting $file
102     endif
103     rm -f $file
104     #calculate new disk free
105     set newused=`du -s |awk '{print $1}'`
106     if ($verb) then
107     echo Now free is $newused
108     endif
109     #
110     end
111    
112     #exit three means I had to delete stuff not expired
113     exit 3
114    
115     #