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
*
|
Rev | Line | |
---|
[23099] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use File::Find; |
---|
| 5 | |
---|
| 6 | # The values here are minimum numbers of days. Negative means mtime, |
---|
| 7 | # positive means atime. |
---|
| 8 | my %dirs = ("/tmp" => 2, |
---|
| 9 | "/var/tmp" => 3); |
---|
| 10 | my $days; |
---|
| 11 | |
---|
| 12 | my @usernames = `w -h | awk '{print \$1}' | sort -u`; |
---|
| 13 | my @uids = map { chomp; my ($a,$b,$uid) = getpwnam($_); $uid; } @usernames; |
---|
| 14 | my %uidset; |
---|
| 15 | foreach my $uid (@uids) { |
---|
| 16 | $uidset{$uid} = 1; |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | sub 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 | |
---|
| 37 | foreach 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 | |
---|
| 45 | exit 0; |
---|
Note: See
TracBrowser
for help on using the repository browser.