source: trunk/debathena/debathena/tmp-cleaner/clean-tmp-areas @ 23099

Revision 23099, 974 bytes checked in by ghudson, 16 years ago (diff)
Add a new package containing the tmp cleaner cron job.
  • Property svn:executable set to *
RevLine 
[23099]1#!/usr/bin/perl
2
3use strict;
4use File::Find;
5
6# The values here are minimum numbers of days.  Negative means mtime,
7# positive means atime.
8my %dirs = ("/tmp" => 2,
9            "/var/tmp" => 3);
10my $days;
11
12my @usernames = `w -h | awk '{print \$1}' | sort -u`;
13my @uids = map { chomp; my ($a,$b,$uid) = getpwnam($_); $uid; } @usernames;
14my %uidset;
15foreach my $uid (@uids) {
16    $uidset{$uid} = 1;
17}
18
19sub visit {
20    my ($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_);
21    return if (-b _ || -c _ || -p _ || -S _);
22    return if ($_ eq ".");
23    return if ($uidset{$uid});
24    if (-d _) {
25        return if (-M _ < 2);
26        system "/bin/saferm", "-d", "-q", $_;
27    } else {
28        if ($days < 0) {
29            return if (-M _ < -$days);
30        } else {
31            return if (-A _ < $days);
32        }
33        system "/bin/saferm", $_;
34    }
35}
36
37foreach my $dir (keys(%dirs)) {
38    chdir $dir || die "Can't chdir to $dir";
39    $days = $dirs{$dir};
40    find({wanted => \&visit,
41          bydepth => 1,
42          no_chdir => 1}, ".");
43}
44
45exit 0;
Note: See TracBrowser for help on using the repository browser.