Added more sorting, corrected some spelling, added some notes

This commit is contained in:
bluesaxman 2019-06-26 08:39:39 -06:00
parent 6323bf9614
commit 83d9ccb08d

19
wipe.pl
View File

@ -40,7 +40,7 @@ sub warning {
return 0;
}
# home made uniqu function
# home made uniq function
sub uniq {
my %seen;
return grep { !$seen{$_}++} @_;
@ -53,11 +53,14 @@ sub getdisks {
foreach(split("\n",$devices)) {
my $devicepath = $_;
my $serial = `udevadm info --query=all --name=$_ | grep SERIAL_SHORT | sed -e 's/^.*=//'`;
my $model = `udevadm info --query=all --name=$_ | grep ID_MODEL | sed -e 's/^.*=//'`;
chomp( $serial );
chomp( $model );
if ( $serial ) {
print $devicepath."\t".$serial."\n";
$listhash{$_}{"path"} = $devicepath;
$listhash{$_}{"serial"} = $serial;
$listhash{$_}{"model"} = $model;
} else { next; }
}
return %listhash;
@ -67,15 +70,15 @@ sub getdisks {
sub wipethemdrives {
my $diskid = shift;
my $disks = shift;
# Write
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, ">", "./test") or warning("could not open "."./test");
print $diskw $clobber;
close($diskw);
system("sync");
print "Wipe attempt complete, checking...\n";
# Read
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);
my $disksum = md5_base64($diskdata);
@ -115,7 +118,7 @@ sub smartcheck {
$disks->{$diskid}{"smart"}{$smartdata[0]}{"raw_value"} = $smartdata[9];
}
close( $smartcommand );
for my $smartentry (keys %{$disks->{$diskid}{"smart"}}) {
for my $smartentry (keys %{$disks->{$diskid}{"smart"}}) { # I want to have this sort before executing the for loop
if ($disks->{$diskid}{"smart"}{$smartentry}{"id"} =~ /0x05|0x07|0xc4|0xc5|0xc6|0xc7/) {
print $disks->{$diskid}{"smart"}{$smartentry}{"id"}." ".$disks->{$diskid}{"smart"}{$smartentry}{"name"}."\t".$disks->{$diskid}{"smart"}{$smartentry}{"raw_value"}."\t";
if ($disks->{$diskid}{"smart"}{$smartentry}{"raw_value"} =~ /0|0\/0/) {
@ -147,19 +150,19 @@ while () {
$disks{$diskid}{"smartpass"} = smartcheck($diskid,\%disks);
if ($disks{$diskid}{"smartpass"} == 1) {
print "Smart looks good.\n";
push(@good, $disks{$diskid}{"serial"});
push(@good, $disks{$diskid}{"serial"}."\t".$disks{$diskid}{"model"});
} else { push(@failed, $disks{$diskid}{"serial"}); }
} else { push(@failed, $disks{$diskid}{"serial"}); }
print "="x80;
print "\n"x5;
}
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 $color{"green"}.join("\n",sort {$a cmp $b} uniq(@good)).$color{"reset"};
anykey("\nHit 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";
print $color{"green"}."-"x34.$color{"red"}."\nWipe complete, insert more drives.\n".$color{"green"}."-"x34."\n";
anykey("Hit any key when ready to continue...\n");
}