use POSIX; my $timestamp; # eg 10/24/2011 5:01:22 PM my $size; # size of file will be bytes my @inp; #array for input files my $outfile; #second argument the output my $statfile; #third argument the status # open status and report in progress. Will abort if status file already here if (-e $ARGV[2]) { die "status file already exists!"; } open(STAT, ">", $ARGV[2]) || die "can't create statfile $ARGV[2]"; print STAT "inprogress"; close(STAT); #quit unless we have the correct number of command-line args my $num_args = $#ARGV + 1; if ($num_args != 3) { print "\nUsage: perl sizeDateValidator.pl \n"; open(STAT, ">", $ARGV[2]) || die "can't create statfile $ARGV[2]"; print STAT "error1"; close(STAT); exit; } #grab files to validate from first argument which should be a readable file if (-e $ARGV[0]) { open(FILE, "<", $ARGV[0]) || die "Can't open file $ARGV[0]"; @inp = ; chomp @inp; close FILE; } else { open(STAT, ">", $ARGV[2]) || die "can't create statfile $ARGV[2]"; print STAT "error2"; close(STAT); exit; } #check to make sure output file doesn't already exist like from previous run. #don't want to overwrite anything I shouldn't $outfile = $ARGV[1]; if (-e $outfile) { open(STAT, ">", $ARGV[2]) || die "can't create statfile $ARGV[2]"; print STAT "error3"; close(STAT); exit; } #for each file in list, get size and timestamp #if the element is not a file, report this #write this to output file passed in as argument. open(FILE, ">", $outfile) || die "Can't open file $outfile"; foreach my $files(@inp){ $files =~ s/"//g; if (-f $files) { $timestamp = POSIX::strftime("%m/%d/%Y %I:%M %p", localtime(( stat $files)[9])); # or change localtime to gmtime $size = (stat $files)[7]; print FILE "$files|$size|$timestamp\n"; } else { print FILE "$files|notfound|notfound\n"; } } close(FILE); open(STAT, ">$ARGV[2]") || die "can't create statfile $ARGV[2]"; print STAT "success"; close(STAT);