Created
October 25, 2016 15:46
-
-
Save anthony-kam/719515776e8c7183580cc6af0958608d to your computer and use it in GitHub Desktop.
Check SMART with software or hardware raid (MegaRaid)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Prerequisites : | |
# smartmontools - Sudo command & espacially (sudo /usr/sbin/smartctl). | |
# MegaCli (MegaRAID) if needed. | |
# HP ACU Cli (HP RAID) if needed. | |
## Inside your file /etc/sudoers: | |
# backup ALL= NOPASSWD: sudo /sbin/MegaCli -pdlist -a0 | |
# backup ALL= NOPASSWD: sudo /usr/sbin/smartctl | |
# backup ALL= NOPASSWD: /sbin/fdisk -l | |
## To have the Device ID for all MegaRAID disks: | |
# sudo /sbin/MegaCli -pdlist -a0 | grep 'Device Id' | sed 's/Device Id: //' | sort | |
function smartctl_homemade { | |
interval=300 | |
hw_raid=$(lspci -knn | grep 'RAID bus controller') | |
if $(echo $hw_raid | grep -q MegaRAID); then | |
# We've MegaRAID | |
# To have temperature (194) on /dev/sda for each disk managed by MegaRAID : | |
for deviceid in $(sudo /sbin/MegaCli -pdlist -a0 | grep 'Device Id' | sed 's/Device Id: //' | sort); | |
do | |
echo -n "PUTVAL \"$(hostname)/homemade_smart/gauge-temperature-deviceid-$deviceid\" interval=$interval N:" | |
sudo /usr/sbin/smartctl -d megaraid,$deviceid -a /dev/sda | egrep '^\s?\s?194' | awk {'print $10'} | |
done | |
# Same for Power_Cycle_Count (12) | |
for deviceid in $(sudo /sbin/MegaCli -pdlist -a0 | grep 'Device Id' | sed 's/Device Id: //' | sort) | |
do | |
echo -n "PUTVAL \"$(hostname)/homemade_smart/gauge-power_cycle_count-deviceid-$deviceid\" interval=$interval N:" | |
sudo /usr/sbin/smartctl -d megaraid,$deviceid -a /dev/sda | egrep '^\s?\s?12' | awk {'print $10'} | |
done | |
# Same for Power_On_Hours (9) | |
for deviceid in $(sudo /sbin/MegaCli -pdlist -a0 | grep 'Device Id' | sed 's/Device Id: //' | sort) | |
do | |
echo -n "PUTVAL \"$(hostname)/homemade_smart/gauge-power_on_hours-deviceid-$deviceid\" interval=$interval N:" | |
sudo /usr/sbin/smartctl -d megaraid,$deviceid -a /dev/sda | egrep '^\s?\s?9' | awk {'print $10'} | |
done | |
# Same for Reallocated_Sector_Ct (5) | |
for deviceid in $(sudo /sbin/MegaCli -pdlist -a0 | grep 'Device Id' | sed 's/Device Id: //' | sort) | |
do | |
echo -n "PUTVAL \"$(hostname)/homemade_smart/gauge-reallocated_sector_ct-deviceid-$deviceid\" interval=$interval N:" | |
sudo /usr/sbin/smartctl -d megaraid,$deviceid -a /dev/sda | egrep '^\s?\s?5' | awk {'print $10'} | |
done | |
elif $(echo $hw_raid | grep -q Hewlett-Packard); the | |
echo "On a du RAID Hewlett-Packard" | |
# To be completed. | |
else | |
# We're using Software RAID or we don't use RAID, or this script doesn't currently support this RAID HW. | |
for partition in $(sudo /sbin/fdisk -l | egrep -o '[hsv]d.' | sort | uniq) | |
do | |
generic=$(sudo /usr/sbin/smartctl -a /dev/$partition) | |
celsius=$(echo "$generic" | egrep '^\s?\s?194' | awk {'print $10'} ; if [[ "${PIPESTATUS[1]}" -ne 0 ]] ; then echo "0" ; fi) && echo -n "PUTVAL \"$(hostname)/homemade_smart/gauge-temperature-$partition\" interval=$interval N:$celsius" && echo | |
Power_Cycle_Count=$(echo "$generic" | egrep '^\s?\s?12' | awk {'print $10'}) && echo -n "PUTVAL \"$(hostname)/homemade_smart/gauge-power_cycle_count-$partition\" interval=$interval N:$Power_Cycle_Count" && echo | |
Power_On_Hours=$(echo "$generic" | egrep '^\s?\s?9' | awk {'print $10'}) && echo -n "PUTVAL \"$(hostname)/homemade_smart/gauge-power_on_hours-$partition\" interval=310 N:$Power_On_Hours" && echo | |
Reallocated_Sector_Ct=$(echo "$generic" | egrep '^\s?\s?5' | awk {'print $10'}) && echo -n "PUTVAL \"$(hostname)/homemade_smart/gauge-reallocated_sector_ct-$partition\" interval=$interval N:$Reallocated_Sector_Ct" && echo | |
done | |
fi | |
} | |
while true; do | |
smartctl_homemade | |
sleep $interval | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 53 : elif $(echo $hw_raid | grep -q Hewlett-Packard); then