minor syntax corrections and output adjustments

This commit is contained in:
bluesaxman 2019-10-28 11:15:43 -06:00
parent 97e3b5f41e
commit 5a8d07e678

24
wipe.pl
View File

@ -93,14 +93,16 @@ sub getdisks {
return %listhash; return %listhash;
} }
# To whip a drive # To whipe a drive
sub wipethemdrives { sub wipethemdrives {
my $diskid = shift; my $diskid = shift;
my $disks = shift; my $disks = shift;
# Write # Write
say "$disks->{$diskid}{path} - Serial:$disks->{$diskid}{serial} is being wiped..."; say "$disks->{$diskid}{path} - Serial:$disks->{$diskid}{serial} is being wiped...";
my $disksum; my $disksum;
my $spacer = 29;
if ($notreally) { if ($notreally) {
$spacer = 18;
print "Pretend wipe complete, pretending to check..."; print "Pretend wipe complete, pretending to check...";
$disksum = $clobsum; $disksum = $clobsum;
} else { } else {
@ -118,16 +120,12 @@ sub wipethemdrives {
} }
# say "Disk Checksum: $disksum"; # say "Disk Checksum: $disksum";
if ($disksum eq $clobsum) { if ($disksum eq $clobsum) {
say +("."x28)."Checksum $color{green}PASSED!!!$color{reset}"; say +("."x$spacer)."Checksum $color{green}PASSED$color{reset}";
# say "$disks->{$diskid}{path} is clean."; # say "$disks->{$diskid}{path} is clean.";
return 1; return 1;
} else { } else {
# say "Wipe Checksum: $clobsum"; # say "Wipe Checksum: $clobsum";
say +("."x28)."Checksum $color{red}FAILED!!!$color{reset}"; say +("."x$spacer)."Checksum $color{red}FAILED$color{reset}";
# this code will not work on the majority of terminals,
# now that we support anything with a terminfo entry.
# printf("%-37.37s %9.9s\n", "Checksum ","$color{red}FAILED!!!$color{reset}");
# say "$disks->{$diskid}{path} did not take, it could be bad.";
return 0; return 0;
} }
} }
@ -137,11 +135,11 @@ sub smartcheck {
# Do our smart disk thing... # Do our smart disk thing...
my $diskid = shift; my $diskid = shift;
my $disks = shift; my $disks = shift;
say "Checking overall-health self-assessment test result: "; print "Checking overall-health self-assessment test result: ".(" "x19);
(my $smartassess = `smartctl /dev/sda -H | grep overall`) or (say "$!\ncould not check smart data, skipping" and return 1); (my $smartassess = `smartctl /dev/sda -H | grep overall`) or (say "$!\ncould not check smart data, skipping" and return 1);
$disks->{$diskid}{smart}{selftest} = (split(": ", $smartassess))[1]; $disks->{$diskid}{selftest} = (split(": ", $smartassess))[1];
if ( "FAILED" == $disks->{$diskid}{smart}{selftest} ) { say "$color{red}Failed$color{reset}"; return 0 if ( "FAILED" eq $disks->{$diskid}{selftest} ) { say "$color{red}Failed$color{reset}"; return 0
} else { say "$color{green}Passed$color{reset}\n"; } } else { say "$color{green}Passed$color{reset}"; }
say "Checking S.M.A.R.T. variables..."; say "Checking S.M.A.R.T. variables...";
# say qq(smartctl $disks->{$diskid}{path} -A -f hex,id | grep "^0x"); # say qq(smartctl $disks->{$diskid}{path} -A -f hex,id | grep "^0x");
(my $smartcommand = `smartctl $disks->{$diskid}{path} -A -f hex,id | grep "^0x"`) or (say "$!\ncould not check smart data, skipping" and return 1); (my $smartcommand = `smartctl $disks->{$diskid}{path} -A -f hex,id | grep "^0x"`) or (say "$!\ncould not check smart data, skipping" and return 1);
@ -180,7 +178,7 @@ while () {
foreach my $diskid (sort {$disks{$a}{serial} cmp $disks{$b}{serial}} keys %disks) { foreach my $diskid (sort {$disks{$a}{serial} cmp $disks{$b}{serial}} keys %disks) {
say $disks{$diskid}{serial}; say $disks{$diskid}{serial};
} }
exit unless "\n" eq anykey("Last chance to save your data, hit ENTER to DESTROY ALL DATA, or any other key to abort!\n"); # exit unless "\n" eq anykey("Last chance to save your data, hit ENTER to DESTROY ALL DATA, or any other key to abort!\n");
foreach my $diskid (sort {$a cmp $b}keys %disks) { foreach my $diskid (sort {$a cmp $b}keys %disks) {
print "="x33; print "="x33;
printf '[ %-10s ]', $diskid; printf '[ %-10s ]', $diskid;
@ -190,7 +188,7 @@ while () {
$disks{$diskid}{smartpass} = smartcheck($diskid,\%disks); $disks{$diskid}{smartpass} = smartcheck($diskid,\%disks);
if ($disks{$diskid}{smartpass} == 1) { if ($disks{$diskid}{smartpass} == 1) {
push(@good, sprintf("%-26.26s\t%46.46s",$disks{$diskid}{serial},$disks{$diskid}{model})); 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, sprintf("%-26.26s\t%46.46s",$disks{$diskid}{serial},$disks{$diskid}{model})); }
} else { push(@failed, $disks{$diskid}{serial}); } } else { push(@failed, $disks{$diskid}{serial}); }
print "="x80; print "="x80;
print "\n"x5; print "\n"x5;