added good list, refined lists to only show serial numbers once, sorted lists

This commit is contained in:
bluesaxman 2019-06-24 11:22:30 -06:00
parent e75831439a
commit 6323bf9614

29
wipe.pl
View File

@ -4,19 +4,24 @@ use warnings;
use Digest::MD5 "md5_base64"; use Digest::MD5 "md5_base64";
use POSIX; use POSIX;
# create our random data and store it in ram so we can keep reusing it
open (my $drand, "<", "/dev/urandom"); open (my $drand, "<", "/dev/urandom");
my $clobber; my $clobber;
read($drand, $clobber, 10240000); read($drand, $clobber, 10240000);
close($drand); close($drand);
my $clobsum = md5_base64($clobber); my $clobsum = md5_base64($clobber);
# define some colors for conviniance
my %color = ( my %color = (
"red" => "\e[0;31m", "red" => "\e[0;31m",
"green" => "\e[0;32m", "green" => "\e[0;32m",
"reset" => "\e[0m" "reset" => "\e[0m"
); );
my @failed = (); my @failed = ();
my @good = ();
my $term = POSIX::Termios->new; my $term = POSIX::Termios->new;
# for providing a waiting prompt
sub anykey { sub anykey {
print shift; print shift;
my $key; my $key;
@ -29,11 +34,19 @@ sub anykey {
return $key return $key
} }
# to handle errors without using die
sub warning { sub warning {
print shift; print shift;
return 0; return 0;
} }
# home made uniqu function
sub uniq {
my %seen;
return grep { !$seen{$_}++} @_;
}
# To get the list of devices we will be cleaning
sub getdisks { sub getdisks {
my $devices = `find /dev/sd*`; my $devices = `find /dev/sd*`;
my %listhash = (); my %listhash = ();
@ -50,17 +63,18 @@ sub getdisks {
return %listhash; return %listhash;
} }
# To while a drive
sub wipethemdrives { sub wipethemdrives {
my $diskid = shift; my $diskid = shift;
my $disks = shift; my $disks = shift;
print $disks->{$diskid}{"path"}." - Serial:".$disks->{$diskid}{"serial"}." is being wiped...\n"; print $disks->{$diskid}{"path"}." - Serial:".$disks->{$diskid}{"serial"}." is being wiped...\n";
open(my $diskw, ">", $disks{$diskid}{"path"}) or return warning("could not open ".$disks{$diskid}{"path"}); open(my $diskw, ">", $disks->{$diskid}{"path"}) or return warning("could not open ".$disks->{$diskid}{"path"});
# open(my $diskw, ">", "./test") or warning("could not open "."./test"); # open(my $diskw, ">", "./test") or warning("could not open "."./test");
print $diskw $clobber; print $diskw $clobber;
close($diskw); close($diskw);
system("sync"); system("sync");
print "Wipe attempt complete, checking...\n"; print "Wipe attempt complete, checking...\n";
open(my $diskr, "<", $disks{$diskid}{"path"}) or return warning("could not open ".$disks{$diskid}{"path"}); open(my $diskr, "<", $disks->{$diskid}{"path"}) or return warning("could not open ".$disks->{$diskid}{"path"});
# open(my $diskr, "<", "./test") or warning("could not open "."./test"); # open(my $diskr, "<", "./test") or warning("could not open "."./test");
my $diskdata; my $diskdata;
read($diskr, $diskdata, 10240000); read($diskr, $diskdata, 10240000);
@ -79,6 +93,7 @@ sub wipethemdrives {
} }
} }
# to test a drive
sub smartcheck { sub smartcheck {
# Do our smart disk thing... # Do our smart disk thing...
my $diskid = shift; my $diskid = shift;
@ -112,6 +127,7 @@ sub smartcheck {
return 1; return 1;
} }
# main loop
while () { while () {
my %disks = getdisks(); my %disks = getdisks();
my $batchcount = keys %disks; my $batchcount = keys %disks;
@ -131,14 +147,19 @@ while () {
$disks{$diskid}{"smartpass"} = smartcheck($diskid,\%disks); $disks{$diskid}{"smartpass"} = smartcheck($diskid,\%disks);
if ($disks{$diskid}{"smartpass"} == 1) { if ($disks{$diskid}{"smartpass"} == 1) {
print "Smart looks good.\n"; print "Smart looks good.\n";
push(@good, $disks{$diskid}{"serial"});
} else { push(@failed, $disks{$diskid}{"serial"}); } } else { push(@failed, $disks{$diskid}{"serial"}); }
} else { push(@failed, $disks{$diskid}{"serial"}); } } else { push(@failed, $disks{$diskid}{"serial"}); }
print "="x80; print "="x80;
print "\n"x5; print "\n"x5;
} }
print "The folowing drives did not wipe successfully,\nThey may need another attempt or they may be bad.\n"; print "These drives were successfully wiped and passed SMART, they may be put back into production:\n";
print join("\n",@failed); print join("\n",sort {$a cmp $b} uniq(@good));
anykey("Hit any key to see the list of failed drives. Please also note any drives that do not appear\non ether list. Those should be tried again (if they do not show up after three times assume falure).");
print "The folowing drives are bad, RMA or shred:\n";
print join("\n",sort {$a cmp $b} uniq(@failed));
@failed = (); @failed = ();
@good = ();
print "\nWipe complete, insert more drives.\n"; print "\nWipe complete, insert more drives.\n";
anykey("Hit any key when ready to continue...\n"); anykey("Hit any key when ready to continue...\n");
} }