#!/usr/bin/perl use Getopt::Std; # Routine to check for the existence of all files listed in a volume index. # # Format: % check_index -i -o offset -l length index_file report_file # # -i = ignore missing data files # -s = start byte of file name # -l = length of file name field # # This routine may be run from anywhere. # # 02 Feb 2006, ACR. # #============================================================================ getopts('io:l:'); $name_start = ($opt_o)? $opt_o : 15; $name_length = ($opt_l)? $opt_l : 50; if (@ARGV != 2) { die "Usage: check_index -i -o offset -l length index_file report_file\n"; } $CUMINDEX = $ARGV[0]; $VOLROOT = "/mnt/pdsraid02/volume"; $OUTFILE = $ARGV[1]; # First, open the files: open (IDX,$CUMINDEX) || die "Could not open $CUMINDEX ($!)"; open (OUT,">$OUTFILE") || die "Could not open $OUTFILE ($!)"; printf OUT "Missing files: \n"; $missing_count = 0; $no_data = 0; # Now we loop: while ($line=) { $vol = substr($line,1,11); $label = substr($line,$name_start,$name_length); $vol =~ tr/A-Z/a-z/; $vol =~ s/-/_/; # Work aroung a stupid typo $label =~ tr/A-Z/a-z/; $label =~ s/\s+//g; # Assemble the label file name and check for existence: $file = "$VOLROOT/$vol/$label"; if (! -e $file) { printf OUT " $vol/$label\n"; $missing_count++; next; } # If it's a detached label file (ends in ".lbl"), check for a ".fit" or # ".tab" file to go with it: if ((! $opt_i) && ($file =~ /\.lbl/)) { $fit = $file; $fit =~ s/\.lbl/.fit/; $tab = $file; $tab =~ s/\.lbl/\.tab/; if ((! -e $fit) && (! -e $tab)) { printf OUT " $file ....... NO DATA FILE?\n"; $no_data++; } } # Next. } # Report totals, close up files and we're done: close(IDX); #printf STDOUT "\n$missing_count Missing label files; $no_data ? data files\n"; printf OUT "\n$missing_count Missing label files; $no_data ? data files\n"; close(OUT);