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 POSIX;
# create our random data and store it in ram so we can keep reusing it
open (my $drand, "<", "/dev/urandom");
my $clobber;
read($drand, $clobber, 10240000);
close($drand);
my $clobsum = md5_base64($clobber);
# define some colors for conviniance
my %color = (
"red" => "\e[0;31m",
"green" => "\e[0;32m",
"reset" => "\e[0m"
);
my @failed = ();
my @good = ();
my $term = POSIX::Termios->new;
# for providing a waiting prompt
sub anykey {
print shift;
my $key;
@ -29,11 +34,19 @@ sub anykey {
return $key
}
# to handle errors without using die
sub warning {
print shift;
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 {
my $devices = `find /dev/sd*`;
my %listhash = ();
@ -50,17 +63,18 @@ sub getdisks {
return %listhash;
}
# To while a drive
sub wipethemdrives {
my $diskid = shift;
my $disks = shift;
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");
print $diskw $clobber;
close($diskw);
system("sync");
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");
my $diskdata;
read($diskr, $diskdata, 10240000);
@ -79,6 +93,7 @@ sub wipethemdrives {
}
}
# to test a drive
sub smartcheck {
# Do our smart disk thing...
my $diskid = shift;
@ -112,6 +127,7 @@ sub smartcheck {
return 1;
}
# main loop
while () {
my %disks = getdisks();
my $batchcount = keys %disks;
@ -131,14 +147,19 @@ while () {
$disks{$diskid}{"smartpass"} = smartcheck($diskid,\%disks);
if ($disks{$diskid}{"smartpass"} == 1) {
print "Smart looks good.\n";
push(@good, $disks{$diskid}{"serial"});
} else { push(@failed, $disks{$diskid}{"serial"}); }
} else { push(@failed, $disks{$diskid}{"serial"}); }
print "="x80;
print "\n"x5;
}
print "The folowing drives did not wipe successfully,\nThey may need another attempt or they may be bad.\n";
print join("\n",@failed);
print "These drives were successfully wiped and passed SMART, they may be put back into production:\n";
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 = ();
@good = ();
print "\nWipe complete, insert more drives.\n";
anykey("Hit any key when ready to continue...\n");
}