From d6b1706e97cf7c308dbb32efb328f6853a32ee25 Mon Sep 17 00:00:00 2001 From: bluesaxman Date: Wed, 8 Sep 2021 15:03:05 -0600 Subject: [PATCH] Changed from sync to hdparm kernel command to solve write caching problem, added failure details to end readout. --- wipe.pl | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/wipe.pl b/wipe.pl index 1bc4623..fabbf58 100755 --- a/wipe.pl +++ b/wipe.pl @@ -112,16 +112,17 @@ sub wipethemdrives { $disksum = $clobsum; $disksum2 = $clobsum; } else { + system("hdparm -W 0 ".$disks->{$diskid}{path}) and do { + print "Cannot turn off drive write caching: $!\n" + print "Disk considered $color{red}FAILED$color{reset}\n"; + $disks->{$diskid}{failure} = "Cannot turn off write caching"; + return 0; + }; open(my $diskw, ">", $disks->{$diskid}{path}) or return warning("could not open $disks->{$diskid}{path}"); print $diskw $clobber; #Start of Disk seek($diskw,-10240000,2); print $diskw $clobber; #End of Disk close($diskw); - system("sync ".$disks->{$diskid}{path}) and do { - #if sync failes disk fails - print "\nWipe attemped $color{red}FAILED$color{reset}\n"; - return ($? >> 8); - }; print "Wipe attempt complete, checking..."; # Read open(my $diskr, "<", $disks->{$diskid}{path}) or return warning("could not open $disks->{$diskid}{path}"); @@ -140,10 +141,12 @@ sub wipethemdrives { say +("."x$spacer)."Checksum $color{green}PASSED$color{reset}"; } else { say +("."x$spacer)."Checksum $color{red}FAILED$color{reset}"; + $disks->{$diskid}{failure} = "Raid wipe failed"; return 0; } } else { say +("."x$spacer)."Checksum $color{red}FAILED$color{reset}"; + $disks->{$diskid}{failure} = "Main Wipe failed"; return 0; } # If long flag than zero whole disk and give a progress bar @@ -172,7 +175,10 @@ sub smartcheck { print "Checking overall-health self-assessment test result: ".(" "x19); (my $smartassess = `smartctl $disks->{$diskid}{path} -H | grep overall`) or (say "\n$!\ncould not check smart data, skipping" and return 1); $disks->{$diskid}{selftest} = (split(": ", $smartassess))[1]; - if ( "FAILED" eq $disks->{$diskid}{selftest} ) { say "$color{red}Failed$color{reset}"; return 0 + if ( "FAILED" eq $disks->{$diskid}{selftest} ) { + say "$color{red}Failed$color{reset}"; + $disks->{$diskid}{failure} = "General SMART failure"; + return 0 } else { say "$color{green}Passed$color{reset}"; } say "Checking S.M.A.R.T. variables..."; # say qq(smartctl $disks->{$diskid}{path} -A -f hex,id | grep "^0x"); @@ -197,8 +203,11 @@ sub smartcheck { printf("%-6.6s %-26.26s\t%-26.26s\t", $disks->{$diskid}{smart}{$smartentry}{id}, $disks->{$diskid}{smart}{$smartentry}{name}, $disks->{$diskid}{smart}{$smartentry}{raw_value}); if ($disks->{$diskid}{smart}{$smartentry}{raw_value} =~ /0|0\/0/) { say "$color{green}Passed$color{reset}"; - } else { say "$color{red}Failed$color{reset}"; return 0} - + } else { + say "$color{red}Failed$color{reset}"; + $disks->{$diskid}{failure} = "failed on $disks->{$diskid}{smart}{$smartentry}{name}"; + return 0; + } } } return 1; @@ -221,9 +230,9 @@ while () { if ($disks{$diskid}{wipe} == 1) { $disks{$diskid}{smartpass} = smartcheck($diskid,\%disks); if ($disks{$diskid}{smartpass} == 1) { - push(@good, sprintf("%-26.26s\t%46.46s",$disks{$diskid}{serial},$disks{$diskid}{model})); - } else { push(@failed, sprintf("%-26.26s\t%46.46s",$disks{$diskid}{serial},$disks{$diskid}{model})); } - } else { push(@failed, $disks{$diskid}{serial}); } + push(@good, sprintf("%-26.26s\t%46.46s\t%30.30s",$disks{$diskid}{serial},$disks{$diskid}{model}, $disks{$diskid}{failure} or "")); + } else { push(@failed, sprintf("%-26.26s\t%46.46s\t%30.30s",$disks{$diskid}{serial},$disks{$diskid}{model}, $disks{$diskid}{failure} or "")); } + } else { push(@failed, sprintf("%26.26s\t%46.46s\t%30.30s",$disks{$diskid}{serial}, "-"x46, $disks{$diskid}{failure} or "")); } print "="x80; print "\n"x5; }