Disk::SMART - Provides an interface to smartctl to return disk stats and to run tests.
Disk::SMART is an object oriented module that provides an interface to get SMART disk info from a device as well as initiate testing. An exmple script using this module can be found at https://github.com/paultrost/linux-geek/blob/master/sysinfo.pl
use Disk::SMART; my $smart = Disk::SMART->new('/dev/sda', '/dev/sdb'); my $disk_health = $smart->get_disk_health('/dev/sda');
Instantiates the Disk::SMART object
DEVICE - Device identifier of a single SSD / Hard Drive, or a list. If no devices are supplied then it runs get_disk_list() which will return an array of detected sdX and hdX devices.
DEVICE
my $smart = Disk::SMART->new(); my $smart = Disk::SMART->new( '/dev/sda', '/dev/sdb' ); my @disks = $smart->get_disk_list();
Returns Disk::SMART object if smartctl is available and can poll the given device(s).
Disk::SMART
Returns hash of the SMART disk attributes and values
DEVICE - Device identifier of a single SSD / Hard Drive
my %disk_attributes = $smart->get_disk_attributes('/dev/sda');
Returns scalar of any listed errors
DEVICE - Device identifier of a single SSD/ Hard Drive
my $disk_errors = $smart->get_disk_errors('/dev/sda');
Returns the health of the disk. Output is "PASSED", "FAILED", or "N/A". If the device has positive values for the attributes listed below then the status will output that information.
Eg. "FAILED - Reported_Uncorrectable_Errors = 1"
The attributes are:
5 - Reallocated_Sector_Count
187 - Reported_Uncorrectable_Errors
188 - Command_Timeout
197 - Current_Pending_Sector_Count
198 - Offline_Uncorrectable
If Reported_Uncorrectable_Errors is greater than 0 then the drive should be replaced immediately. This list is taken from a study shown at https://www.backblaze.com/blog/hard-drive-smart-stats/
my $disk_health = $smart->get_disk_health('/dev/sda');
Returns list of detected hda and sda devices. This method can be called manually if unsure what devices are present.
$smart->get_disk_list;
Returns the model of the device. eg. "ST3250410AS".
my $disk_model = $smart->get_disk_model('/dev/sda');
Returns an array with the temperature of the device in Celsius and Farenheit, or N/A.
my ($temp_c, $temp_f) = $smart->get_disk_temp('/dev/sda');
Runs the SMART short self test and returns the result.
DEVICE - Device identifier of SSD/ Hard Drive
$smart->run_short_test('/dev/sda');
Updates the SMART output and attributes for each device. Returns undef.
DEVICE - Device identifier of a single SSD / Hard Drive or a list of devices. If none are specified then get_disk_list() is called to detect devices.
$smart->update_data('/dev/sda');
This module should run on any UNIX like OS with Perl 5.10+ and the smartctl progam installed from the smartmontools package.
Paul Trost <ptrost@cpan.org>
Copyright 2015 by Paul Trost This script is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License v2, or at your option any later version. <http://gnu.org/licenses/gpl.html>
To install Disk::SMART, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Disk::SMART
CPAN shell
perl -MCPAN -e shell install Disk::SMART
For more information on module installation, please visit the detailed CPAN module installation guide.