#!/usr/bin/perl

#for file in /scratch/tpc-h/3TB-45/*.tbl.*; do
@files = </scratch/tpc-h/3TB-45/*.tbl.*>;
foreach $file (@files) {
my $localverifyCmd = "md5sum -b $file";
my $localresult = `$localverifyCmd`;
($localmd5sum, $localname) = split(' ', $localresult);
print "File: $file $localmd5sum\n";
}

exit;

#!/usr/bin/perl

my %md5sums;

foreach $file ("SortGrep10GB", "SortGrep20GB", "SortGrep40GB", "SortGrep535MB") {

my $cmd = "scp " . $partner . ":" . $andydir . "/" . $file . " $andydir" . "/" . $file;
print "$cmd\n";
my $sshresults = `$cmd`;
print $sshresults;

my $verifyCmd = "ssh $partner md5sum -b $andydir" . "/" . $file;
print "$verifyCmd\n";
my $result = `$verifyCmd`;
print "got back $result\n";
($md5sum, $name) = split(' ', $result);
print "storing $md5sum in $file\n";
$md5sums{$file} = $md5sum;

my $localverifyCmd = "md5sum -b $andydir" . "/" . $file;
my $localresult = `$localverifyCmd`;
print "got back $localresult\n";


my $localfile = $andydir . "/" . $file;
if(-e $localfile) {
	($localmd5sum, $localname) = split(' ', $localresult);
	if($md5sums{$file} eq $localmd5sum) {
		print "COMPARED: $md5sums{$file} and $localmd5sum\n"; 
		print "VERIFIED\t$hostname\t$andydir\t$file\n";
	} else {
		print "NOCOMPARE: file doesn't exist";
		print"FAILED\t$hostname\t$andydir\t$file\n";
	} 
} else {
	print"FAILED\t$hostname\t$andydir\t$file\n";
}
}

exit;

#foreach $file ("Rankings.dat", "UserVisits.dat", "URLs") {
foreach $file ("Rankings.dat", "URLs") {

my $cmd = "scp " . $partner . ":" . $alexdir . "/" . $file . " $alexdir" . "/" . $file;
print "$cmd\n";
my $sshresults = `$cmd`;
print $sshresults;

my $verifyCmd = "ssh $partner md5sum -b $alexdir" . "/" . $file;
print "$verifyCmd\n";
my $result = `$verifyCmd`;
print "got back $result\n";
($md5sum, $name) = split(' ', $result);
print "storing $md5sum in $file\n";
$md5sums{$file} = $md5sum;

my $localverifyCmd = "md5sum -b $alexdir" . "/" . $file;
my $localresult = `$localverifyCmd`;
print "got back $localresult\n";

my $localfile = $alexdir . "/" . $file;
if(-e $localfile) {
	($localmd5sum, $localname) = split(' ', $localresult);
	if($md5sums{$file} eq $localmd5sum) {
		print "COMPARED: $md5sums{$file} and $localmd5sum\n"; 
		print "VERIFIED\t$hostname\t$alexdir\t$file\n";
	} else {
		print"FAILED\t$hostname\t$alexdir\t$file\n";
	} 
} else {
	print "NOCOMPARE: no such file\n";
	print"FAILED\t$hostname\t$alexdir\t$file\n";
}
}

my $endTime = `date`;
print "End time is $endTime";
