首页 > 代码库 > 监控HP服务器cpu状态脚本
监控HP服务器cpu状态脚本
监控HP服务器cpu状态脚本
脚本1(如有问题则发邮件通知):
# vi cpu.sh
按a或i进入编辑模式
#!/bin/bash
Name=`hostname`
IP=`/sbin/ifconfig eth0 | grep "inet addr" | awk -F[:" "]+ ‘{print $4}‘`
Date=`date +%m%d%y`
Num=`/usr/sbin/dmidecode | grep -i ‘serial number‘ | head -n 1`
CPU=`/sbin/hpasmcli -s "show server" | grep Status | awk -F[:" "]+ ‘{print $2}‘`
CPU2=`/sbin/hpasmcli -s "show server" | grep Speed | awk -F[:" "]+ ‘{print $2}‘ | head -n 1`MHz
i=1;
for OK in $CPU
do
if [ $OK = "Ok" ]
then
i=$(( $i + 1 ))
else
touch /log/$Date.log
echo "$Name($IP) $i cpu($CPU2) is bad" >> /log/$Date.log
echo "$Num" >> /log/$Date.log
/usr/bin/mail -s "$Name($IP) cpu($CPU2) bad" zhi.yang@ming.com < /log/$Date.log
i=$(( $i + 1 ))
fi
done
按Esc退出编辑模式
:wq (保存并退出)
脚本2(每天发邮件通知):
# vi cpu.sh
按a或i进入编辑模式
#!/bin/bash
Name=`hostname`
IP=`/sbin/ifconfig eth0 | grep "inet addr" | awk -F[:" "]+ ‘{print $4}‘`
Date=`date +%m%d%y`
Num=`/usr/sbin/dmidecode | grep -i ‘serial number‘ | head -n 1`
CPU=`/sbin/hpasmcli -s "show server" | grep Status | awk -F[:" "]+ ‘{print $2}‘`
CPU2=`/sbin/hpasmcli -s "show server" | grep Speed | awk -F[:" "]+ ‘{print $2}‘ | head -n 1`
touch /log/$Date.log
i=1;
for OK in $Mem
do
if [ $OK = "Ok" ]
then
echo "$Name($IP) $i cpu($CPU2) is ok" >> /log/$Date.log
i=$(( $i + 1 ))
else
echo "$Name($IP) $i cpu($CPU2) is bad" >> /log/$Date.log
echo "$Num" >> /log/$Date.log
/usr/bin/mail -s "$Name($IP) cpu($CPU2) bad" zhi.yang@ming.com < /log/$Date.log
i=$(( $i + 1 ))
fi
done
按Esc退出编辑模式
:wq (保存并退出)
本文出自 “linux” 博客,谢绝转载!
监控HP服务器cpu状态脚本