/[sysadmin-cookbook]/recepies/smart/smart-test-relocate.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /recepies/smart/smart-test-relocate.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 287 - (hide annotations)
Wed Jan 25 16:53:11 2012 UTC (12 years, 3 months ago) by dpavlin
File MIME type: text/plain
File size: 940 byte(s)
run smart test incrementally and relocate batch of sectors

1 dpavlin 287 #!/usr/bin/perl
2    
3     use warnings;
4     use strict;
5    
6     my $drive = $ARGV[0] || die "usage: $0 /dev/sda\n";
7     my $delay = 15;
8     my $rewrite_sectors = 16;
9    
10     my $test_started = 0;
11    
12     sub smart_test {
13     my $sector = shift;
14     my $cmd = "smartctl -t select,$sector-max $drive";
15     warn "$cmd\n";
16     system $cmd;
17     $test_started = 1;
18     }
19    
20     sub smart {
21     open(my $fh, '-|', "smartctl -l selective $drive");
22     while(<$fh>) {
23     chomp;
24     print "# $_\n";
25     if ( m/Completed_read_failure.*\((\d+)-\d+\)/ ) {
26     my $sector = $1;
27     print "rewrite sector: $sector\n";
28     foreach my $s ( $sector .. $sector + $rewrite_sectors ) {
29     system "hdparm --write-sector $s --yes-i-know-what-i-am-doing $drive";
30     }
31     smart_test $sector;
32     return 1;
33     } elsif ( m/Self_test_in_progress/ ) {
34     return 1;
35     } elsif ( m/Not_testing/ ) {
36     return 1 if $test_started;
37     smart_test 0; # first-time invocation
38     }
39     }
40     return 0;
41     }
42    
43     while ( smart ) {
44     warn "# sleep $delay s\n";
45     sleep $delay;
46     }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26