[26953] | 1 | #!/usr/bin/perl
|
---|
| 2 |
|
---|
| 3 | use strict;
|
---|
| 4 | use warnings;
|
---|
| 5 |
|
---|
| 6 | use Unix::Getrusage;
|
---|
| 7 |
|
---|
| 8 | if (!defined($ENV{'GSDLHOME'}))
|
---|
| 9 | {
|
---|
| 10 | print STDERR "Error! GSDLHOME not in environment (have you sourced setup.bash?)\n";
|
---|
| 11 | exit(0);
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | if (!defined($ARGV[0]))
|
---|
| 15 | {
|
---|
| 16 | print STDERR "Usage: rm_archives.pl <collection name> [<debug>]\n";
|
---|
| 17 | exit(0);
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | # Clean up command...
|
---|
| 21 | my $cmd = 'rm -rf ';
|
---|
| 22 | my $del_count = 0;
|
---|
| 23 |
|
---|
| 24 | # Check the archives directory as a priority
|
---|
| 25 | my $archives_dir = $ENV{'GSDLHOME'} . '/collect/' . $ARGV[0] . '/archives';
|
---|
| 26 | if (-d $archives_dir)
|
---|
| 27 | {
|
---|
| 28 | $cmd .= ' "' . $archives_dir . '"';
|
---|
| 29 | $del_count++;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | # Cache dir too for video or other caching plugins
|
---|
| 33 | my $cached_dir = $ENV{'GSDLHOME'} . '/collect/' . $ARGV[0] . '/cached';
|
---|
| 34 | if (-d $cached_dir)
|
---|
| 35 | {
|
---|
| 36 | $cmd .= ' "' . $cached_dir . '"';
|
---|
| 37 | $del_count++;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | # There may also be a logs directory we'll nuke, for clarity sake
|
---|
| 41 | my $logs_dir = $ENV{'GSDLHOME'} . '/collect/' . $ARGV[0] . '/logs';
|
---|
| 42 | if (-d $logs_dir)
|
---|
| 43 | {
|
---|
| 44 | $cmd .= ' "' . $logs_dir . '"';
|
---|
| 45 | $del_count++;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | # Now run the built up command (assuming we found something to delete)
|
---|
| 49 | if ($del_count > 0)
|
---|
| 50 | {
|
---|
| 51 | if (defined ($ARGV[1]))
|
---|
| 52 | {
|
---|
| 53 | print "CMD: " . $cmd . "\n";
|
---|
| 54 | }
|
---|
| 55 | `$cmd`;
|
---|
| 56 | }
|
---|
| 57 | else
|
---|
| 58 | {
|
---|
| 59 | print "Warning - no previous archives found: " . $archives_dir . "\n";
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | # Write out timing statistics
|
---|
| 63 | if (defined ($ARGV[1]))
|
---|
| 64 | {
|
---|
| 65 | my $rusage_struct = getrusage();
|
---|
| 66 | my $rusage_children_struct = getrusage_children();
|
---|
| 67 | print "\n";
|
---|
| 68 | print "*************************************************\n";
|
---|
| 69 | print "DEBUG: Script Timing/Usage for rm_archives.pl\n";
|
---|
| 70 | print "*************************************************\n";
|
---|
| 71 | my $rusage_fields = {'user time used'=>'ru_utime',
|
---|
| 72 | 'system time used'=>'ru_stime',
|
---|
| 73 | 'maximum resident set size'=>'ru_maxrss',
|
---|
| 74 | 'integral shared memory size'=>'ru_ixrss',
|
---|
| 75 | 'integral unshared data size'=>'ru_idrss',
|
---|
| 76 | 'integral unshared stack size'=>'ru_isrss',
|
---|
| 77 | 'page reclaims'=>'ru_minflt',
|
---|
| 78 | 'page faults'=>'ru_majflt',
|
---|
| 79 | 'swaps'=>'ru_nswap',
|
---|
| 80 | 'block input operations'=>'ru_inblock',
|
---|
| 81 | 'block output operations'=>'ru_oublock',
|
---|
| 82 | 'messages sent'=>'ru_msgsnd',
|
---|
| 83 | 'messages received'=>'ru_msgrcv',
|
---|
| 84 | 'signals received'=>'ru_nsignals',
|
---|
| 85 | 'voluntary context switches'=>'ru_nvcsw',
|
---|
| 86 | 'involuntary context switches'=>'ru_nivcsw'};
|
---|
| 87 | foreach my $rusage_title (sort keys %{$rusage_fields})
|
---|
| 88 | {
|
---|
| 89 | my $rusage_field = $rusage_fields->{$rusage_title};
|
---|
| 90 | my $total = $rusage_struct->{$rusage_field} + $rusage_children_struct->{$rusage_field};
|
---|
| 91 | print ' * ' . sprintf("%-30s", ucfirst($rusage_title) . ': ') . $total . "\n";
|
---|
| 92 | }
|
---|
| 93 | print "*************************************************\n";
|
---|
| 94 | print "\n";
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | exit(0);
|
---|