监控HP服务器cpu状态脚本
脚本1(如有问题则发邮件通知):
# vi cpu.sh按a或i进入编辑模式#!/bin/bashName=`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`MHzi=1;for OK in $CPU do if [ $OK = "Ok" ]then i=$(( $i + 1 )) elsetouch /log/$Date.logecho "$Name($IP) $i cpu($CPU2) is bad" >> /log/$Date.logecho "$Num" >> /log/$Date.log/usr/bin/mail -s "$Name($IP) cpu($CPU2) bad" zhi.yang@ming.com < /log/$Date.log i=$(( $i + 1 )) fidone按Esc退出编辑模式:wq (保存并退出)脚本2(每天发邮件通知):
# vi cpu.sh
按a或i进入编辑模式#!/bin/bashName=`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" ]thenecho "$Name($IP) $i cpu($CPU2) is ok" >> /log/$Date.log
i=$(( $i + 1 ))
elseecho "$Name($IP) $i cpu($CPU2) is bad" >> /log/$Date.logecho "$Num" >> /log/$Date.log/usr/bin/mail -s "$Name($IP) cpu($CPU2) bad" zhi.yang@ming.com < /log/$Date.log i=$(( $i + 1 )) fidone按Esc退出编辑模式:wq (保存并退出)