检查HP服务器硬盘状态脚本(如有问题则发邮件通知):
脚本1(有问题才发邮件):
# vi disk.sh
按a或i进入编辑模式
#!/bin/bash
Name=`hostname`
Date=`date +%m%d%y`
Num=`/usr/sbin/dmidecode | grep -i 'serial number' | head -n 1`
Disk=`/usr/sbin/hpacucli ctrl all show config | grep physicaldrive | awk -F[:" "]+ '{print $15}'`
Disk2=`/usr/sbin/hpacucli ctrl all show config | grep physicaldrive | awk -F[:" "]+ '{print $13}' | head -n 1`
i=1;
for OK in $Disk
do
if [ $OK = "OK)" ]
then
i=$(( $i + 1 ))
elif [ $OK = "Failed)" ] || [ $OK = "Predictive" ]
then
touch /log/$Date.log
echo "$Name $i disk($Disk2) is bad" >> /log/$Date.log
echo "$Num" >> /log/$Date.log
/usr/bin/mail -s "$Name disk bad" zhi.ming@ming.com < /log/$Date.log
i=$(( $i + 1 ))
fi
done
按Esc退出编辑模式
:wq (保存并退出)
脚本2(每天都发邮件):
# vi disk.sh
按a或i进入编辑模式
#!/bin/bash
Name=`hostname`
Date=`date +%m%d%y`
Num=`/usr/sbin/dmidecode | grep -i 'serial number' | head -n 1`
Disk=`/usr/sbin/hpacucli ctrl all show config | grep physicaldrive | awk -F[:" "]+ '{print $15}'`
Disk2=`/usr/sbin/hpacucli ctrl all show config | grep physicaldrive | awk -F[:" "]+ '{print $13}'`
touch /log/$Date.log
i=1;
for OK in $Disk
do
if [ $OK = "OK)" ]
then
echo "$Name $i disk($Disk2) is ok" >> /log/$Date.log
i=$(( $i + 1 ))
elif [ $OK = "Failed)" ] || [ $OK = "Predictive" ]
then
echo "$Name $i disk($Disk2) is bad" >> /log/$Date.log
echo "$Num" >> /log/$Date.log
i=$(( $i + 1 ))
else
echo "$Name $i disk is ok" >> /log/$Date.log
i=$(( $i + 1 ))
/usr/bin/mail -s "$Name disk bad" zhi.ming@ming.com < /log/$Date.log
fi
done
按Esc退出编辑模式
:wq (保存并退出)
转载于:https://blog.51cto.com/yangzhiming/1427253