source: trunk/gsdl/bin/script/cleantmp.pl@ 1780

Last change on this file since 1780 was 1461, checked in by sjboddie, 24 years ago

A few fixes to collectoraction

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1#!/usr/bin/perl
2
3###########################################################################
4#
5# cleantmp.pl
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 1999 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28
29# cleantmp.pl cleans up the gsdl/tmp directory
30# it's intended mainly for use by the collectoraction
31
32BEGIN {
33 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
34 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
35}
36
37use parsargv;
38use util;
39
40sub print_usage {
41 print STDERR "\n usage: $0 [options]\n\n";
42 print STDERR " oprions:\n";
43 print STDERR " -expire_days number The number of days old information in the tmp\n";
44 print STDERR " directory must be before it is removed (defaults\n";
45 print STDERR " to 7 days)\n\n";
46}
47
48&main ();
49
50sub main {
51
52 if (!parsargv::parse(\@ARGV, 'expire_days/\d/7', \$expire_days)) {
53 &print_usage();
54 die "\n";
55 }
56
57 my $current_time = time;
58 my $expire_time = ($current_time - ($expire_days*60*60*24));
59
60 my $tmpdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp");
61
62 opendir (TMP, $tmpdir) || die "cleantmp.pl: couldn't open $tmpdir\n";
63 my @files = readdir TMP;
64 closedir TMP;
65
66 foreach $file (@files) {
67 next if ($file =~ /^\.\.$/);
68
69 if ($file =~ /^tbuild/) {
70 my $thisfile = &util::filename_cat ($tmpdir, $file);
71 my @stats = stat ($thisfile);
72 if ($stats[9] < $expire_time) {
73 &util::rm_r ($thisfile);
74 }
75 }
76 }
77}
Note: See TracBrowser for help on using the repository browser.