You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1019 B
36 lines
1019 B
#!/usr/bin/perl -w
|
|
|
|
use warnings;
|
|
use strict;
|
|
use JSON;
|
|
|
|
my $json;
|
|
@{$json->{data}} = ();
|
|
|
|
opendir(my $dh, "/sys/block") or die "Couldn't open /sys/block: $!";
|
|
my @blocks = grep { $_ !~ m/^\./ } readdir($dh);
|
|
closedir($dh);
|
|
foreach my $block (@blocks){
|
|
my $removable = 0;
|
|
my $size = 1;
|
|
# Skip block we already know they won't support SMART
|
|
next if ($block =~ m/^(ram|loop|md|dm\-)\d+/);
|
|
if ( -e "/sys/block/$block/removable"){
|
|
open REMOVABLE, "/sys/block/$block/removable";
|
|
$removable = join "", <REMOVABLE>;
|
|
close REMOVABLE;
|
|
chomp($removable);
|
|
next if ($removable eq '1');
|
|
}
|
|
if ( -e "/sys/block/$block/size"){
|
|
open SIZE, "/sys/block/$block/size";
|
|
$size = join "", <SIZE>;
|
|
close SIZE;
|
|
chomp($size);
|
|
next if ($size eq '0');
|
|
}
|
|
next unless (system("/usr/sbin/smartctl -A /dev/$block >/dev/null 2>&1") == 0);
|
|
push @{$json->{data}}, { "{#SMARTDRIVE}" => "/dev/$block" };
|
|
}
|
|
print to_json($json);
|
|
exit(0);
|
|
|