From 83d9ccb08d700db0b98ebb32e3e05ecdb2182d7b Mon Sep 17 00:00:00 2001 From: bluesaxman Date: Wed, 26 Jun 2019 08:39:39 -0600 Subject: [PATCH] Added more sorting, corrected some spelling, added some notes --- wipe.pl | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/wipe.pl b/wipe.pl index 872a98f..bfeae01 100755 --- a/wipe.pl +++ b/wipe.pl @@ -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,12 +118,12 @@ 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/) { print $color{"green"}."Passed".$color{"reset"}."\n"; - }else { print $color{"red"}."Failed".$color{"reset"}."\n"; return 0} + } else { print $color{"red"}."Failed".$color{"reset"}."\n"; return 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"); }