Skip to content

Instantly share code, notes, and snippets.

@kyxap1
Last active June 13, 2016 03:07
Show Gist options
  • Save kyxap1/12f021df91ff9d2b865efce5f39b80a1 to your computer and use it in GitHub Desktop.
Save kyxap1/12f021df91ff9d2b865efce5f39b80a1 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
use strict;
use warnings;
chomp( my $OS = qx(uname -o) );
die "Not FreeBSD OS!" if ! $OS =~ /FreeBSD/;
$ENV{'PATH'} = "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin";
my $DEV = "/dev/pass";
#mfi0 Physical Drives:
#( 279G) ONLINE <SEAGATE ST9300603SS FS04 serial=3SE0VTGB> SAS enclosure 1, slot 0
my $re='\(.*?(?<SIZE>(?:[a-zA-Z0-9]+)).*?(?<STATUS>(?:[a-zA-Z0-9]+)).*?(?<VENDOR>(?:[a-zA-Z0-9]+)).*?(?<MODEL>(?:[a-zA-Z0-9]+)).*?(?<FW>(?:[a-zA-Z0-9]+)).*?=(?<SERIAL>(?:[a-zA-Z0-9]+)).*?(?<TYPE>(?:[a-zA-Z0-9]-?)+).*?(?<ENCLOSURE>\d+).*?(?<SLOT>\d+)';
while (<>) {
if ( m/$re/is ) {
my $HOURS;
my $DISK = $DEV . $+{SLOT};
if ( -c $DISK ) {
open(SMART, "smartctl -a $DISK |");
while (<SMART>) {
if ( m/number of hours powered up\s=\s(?<HOURS>\d+)/is ) {
$HOURS = $+{HOURS};
}
}
close(SMART);
}
print "$+{VENDOR} $+{MODEL} $+{SERIAL} $+{FW} $+{SIZE} $HOURS $+{STATUS} $+{TYPE} $+{ENCLOSURE}:$+{SLOT}\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment