Monitor HP Server CPU status script
Script 1 (send an email notification if any problem occurs ):
# Vi CPU. Sh
Press a or I to enter the editing mode.
#! /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" [email protected] </log/$ date. Log
I = $ ($ I + 1 ))
Fi
Done
Press ESC to exit the editing mode
: WQ (save and Exit)
Script 2 (send an email every day ):
# Vi CPU. Sh
Press a or I to enter the editing mode.
#! /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" [email protected] </log/$ date. Log
I = $ ($ I + 1 ))
Fi
Done
Press ESC to exit the editing mode
: WQ (save and Exit)
This article is from the "Linux" blog and will not be reproduced!
Monitor HP Server CPU status script