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

Last change on this file since 18470 was 1970, checked in by sjboddie, 23 years ago

Added more usage information to all perl programs and removed a few
programs that are no longer useful.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 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";
42 print STDERR "cleantmp.pl: Cleans up the Greenstone tmp directory by deleting anything\n";
43 print STDERR " more than -expire_days days old.\n\n";
44 print STDERR "\n usage: $0 [options]\n\n";
45 print STDERR " options:\n";
46 print STDERR " -expire_days number The number of days old information in the tmp\n";
47 print STDERR " directory must be before it is removed (defaults\n";
48 print STDERR " to 7 days)\n\n";
49}
50
51&main ();
52
53sub main {
54
55 if (!parsargv::parse(\@ARGV, 'expire_days/\d/7', \$expire_days)) {
56 &print_usage();
57 die "\n";
58 }
59
60 my $current_time = time;
61 my $expire_time = ($current_time - ($expire_days*60*60*24));
62
63 my $tmpdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp");
64
65 opendir (TMP, $tmpdir) || die "cleantmp.pl: couldn't open $tmpdir\n";
66 my @files = readdir TMP;
67 closedir TMP;
68
69 foreach $file (@files) {
70 next if ($file =~ /^\.\.$/);
71
72 if ($file =~ /^tbuild/) {
73 my $thisfile = &util::filename_cat ($tmpdir, $file);
74 my @stats = stat ($thisfile);
75 if ($stats[9] < $expire_time) {
76 &util::rm_r ($thisfile);
77 }
78 }
79 }
80}
Note: See TracBrowser for help on using the repository browser.