Rewrite disco_smart_sudo in perl and switch to read /sys/block so it can detect smart capable drives with older smartctl
parent
523b45b406
commit
754005c380
1 changed files with 33 additions and 12 deletions
@ -1,13 +1,34 @@ |
|||||||
#!/bin/sh |
#!/usr/bin/perl -w |
||||||
|
|
||||||
echo -e "{\n\t\"data\":[\n\n" |
use warnings; |
||||||
for DISK in $(smartctl --scan-open | cut -d' ' -f1); do |
use strict; |
||||||
smartctl -A $DISK >/dev/null 2>&1 |
use JSON; |
||||||
if [ $? -eq 0 ]; then |
|
||||||
DISK=$(echo $DISK | sed -e 's|/|\\/|g') |
my $json; |
||||||
echo -e "\t{\n" |
@{$json->{data}} = (); |
||||||
echo -e "\t\t\"{#SMARTDRIVE}\":\"$DISK\"" |
|
||||||
echo -e "\t}," |
opendir(my $dh, "/sys/block") or die "Couldn't open /sys/block: $!"; |
||||||
fi |
my @blocks = grep { $_ !~ m/^\./ } readdir($dh); |
||||||
done |
closedir($dh); |
||||||
echo -e "\n\t]\n}\n" |
foreach my $block (@blocks){ |
||||||
|
my $removable = 0; |
||||||
|
my $size = 1; |
||||||
|
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("smartctl -A /dev/$block >/dev/null 2>&1") == 0); |
||||||
|
push @{$json->{data}}, { "{#SMARTDRIVE}" => "/dev/$block" }; |
||||||
|
} |
||||||
|
print to_json($json); |
||||||
|
exit(0); |
||||||
|
Loading…
Reference in new issue