#!/usr/bin/perl #checkem # goes through moveme list # gets checksums of each file # compares them # if equivalent, deletes old file # jody DeRidder # 6/26/09 $test = "./test"; $move = "./moveme"; open (MOVE, $move) or die "can't read in $move\n"; while ($line = ){ undef (@files); if ($line =~ /^(\S+) *(\S+)$/){ $a = $1; $b = $2; if (-e $a){ if (-e $b){ `md5sum "$a" > "$test"`; `md5sum "$b" >> "$test"`; } else{ print "ERROR: $b does not exist\n"; next;} } else{ print "ERROR: $a does not exist\n"; next;} open (TEST, $test) or die "can't read $test\n"; $count = 0; while ($line = ){ if ($line =~ /^(\S+) *(\S+)$/){ $md = $1; $file = $2; $nums[$count] = $md; $files[$count] = $file; print $line; $count ++; } } close (TEST); unlink ($test); print "comparing $nums[0] for $files[0] against \n $nums[1] for $files[1]\n"; if ($nums[0] eq $nums[1]){ # safe to delete one $old = $files[0]; unlink ($old); print "deleting $old\n"; } else{ print "ERROR: $files[0] does not equal $files[1]\n"; } } } close (MOVE);