root/trunk/devel/Utils/fuzzy-cleantmp

Revision 133, 1.5 KB (checked in by decoder, 3 years ago)

Added License tags too all code files

Line 
1#!/usr/local/bin/perl
2#
3# <@LICENSE>
4# Licensed to the Apache Software Foundation (ASF) under one or more
5# contributor license agreements.  See the NOTICE file distributed with
6# this work for additional information regarding copyright ownership.
7# The ASF licenses this file to you under the Apache License, Version 2.0
8# (the "License"); you may not use this file except in compliance with
9# the License.  You may obtain a copy of the License at:
10#
11#     http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18# </@LICENSE>
19
20opendir TMP, "/tmp" or die "Cannot read /tmp\n";
21my @files = grep {m/spamassassin/} readdir TMP;
22closedir TMP;
23
24my $hours = shift @ARGV || 12;
25my $limit = time - ($hours * 3600);
26printf "Removing tempfiles older than %s\n",scalar(localtime($limit));
27foreach my $d (@files) {
28    my $df = "/tmp/" . $d;
29    next unless -d $df;
30    my @stat = stat $df;
31    next if $stat[9] > $limit;
32    printf "$d -> %s\n",scalar(localtime($stat[9]));
33    opendir TMP, $df or die "Cannot read $df\n";
34    my @dfs = readdir TMP;
35    closedir TMP;
36    foreach my $f (@dfs) {
37        next if $f eq '.';
38        next if $f eq '..';
39        my $fn = sprintf "%s/%s",$df,$f;
40        unlink $fn;
41    }
42    rmdir $df;
43}
Note: See TracBrowser for help on using the browser.