#!/bin/sh
#
# Load the configuration file first, if the profile does not exist, the error exits
#
Source= $HOME/config/config
Check_source ()
{
If [-R $SOURCE]; Then
. $SOURCE
Else
echo "$ (basename $): Cannot locate the default setting file."
Exit 1
Fi
}
#
# define Report Headers
#
Report_Header ()
{
hostip=$ (ifconfig-a | sed-n ' 2p ' |awk ' {print $} ')
hostname=$ (HOSTNAME)
User= ' Who am I | Cut-d ""-f1 '
cat<<!
Hostname: $HOSTNAME Server: $HOSTIP
User: $USER Time: $ (Date +%y '-'%m '-'%d '%H ': '%m ': '%s ')
SYSTEM CHECK
===================
!
}
#
# define the directory and log file name of the log files and set the current user directory to Log_path
#
log_path=$ (Echo $HOME)
log_file= $LOG _path/log ' Date +%y%m%d%h%m%s '
#
# Backup History files
#
CD $LOG _path
Test-f log2007*
If ["$?"-eq 0];then
MV $LOG _path/log2007* $LOG _path/niyl/>/dev/null 2>&1
Else
:
Fi
#define TEMP directory, if not exist,create temp directory.
Temp_path= $LOG _path/temp
If [D-$TEMP _path];then
:
Else
mkdir $TEMP _path
Fi
#
# Load Environment settings
#
Check_source
#
# Output Report Header information
#
Report_Header >> $LOG _file
# Check CPU usage, use the Vmstat command here
echo "***************************************** Check CPU *****************************************" >> $LOG _ FILE
Vmstat 1 10 | awk ' {print $0;if ($ ~/^[0-9].*/) (totalcpu+=$16);(AVECPU=100-TOTALCPU/10)}; End {print "The average usage of
CPU is: "Avecpu} ' > $TEMP _path/cpu_info
Cat $TEMP _path/cpu_info >> $LOG _file
Cpu_used_pct= ' Cat $TEMP _path/cpu_info | grep "The average usage of CPU is" |awk-f ":" ' {print $} '
If ["$cpu _used_pct"-gt "$CPU _value"]; Then
echo "log-warnning: ' Date +%y '-'%m '-'%d ' '%H ': '%m ': '%s ', the CPU load exceeds the threshold setting, please check system!!" >> $LOG _file
Else
echo "\t\t\t\t CPU load normal!!" >> $LOG _file
Fi
#
# Memory usage monitoring, including swap area usage monitoring
#
echo >> $LOG _file
echo >> $LOG _file
echo "***************************************** check memory useage *****************************************" > > $LOG _file
Cat $TEMP _path/cpu_info | awk ' {print $0;if ($ ~/^[0-9].*/) (totalpi+=$6) (totalpo+=$7)}; \
End {if (totalpi<10 && totalpo<10) print "\t\t\t\tmemory load normal!!"; if (totalpi>10 | | totalpo>10) PRINT Memory load exception, please check
Check the system!! "}" >> $LOG _file
#
# Check disk space. ÷
#
echo >> $LOG _file
echo >> $LOG _file
echo "***************************************** Check disk space *****************************************" >> $LOG _file
Df-k >> $LOG _file
Df-k |grep-v proc |grep-v filesystem |awk ' {x=1*$4}{print $ ', ' $ ', ' $ ', ' $ ', ' $ ', ' $ ', ' $} ' > $TEMP _path/disk_info
Cat $TEMP _path/disk_info | Grep-v ' ^# ' | While Read line
Todo
item1=$ (echo $line | awk-f ', ' {print $} ')
item2=$ (echo $line | awk-f ', ' {print $} ')
item3=$ (echo $line | awk-f ', ' {print $} ')
item4=$ (echo $line | awk-f ', ' {print $} ' |awk-f '% ' {print} ')
item5=$ (echo $line | awk-f ', ' {print $} ')
item6=$ (echo $line | awk-f ', ' {print $} ')
item7=$ (echo $line | awk-f ', ' {print $} ')
If ["$item 4"-gt "$DISK _value"]; Then
Echo ' log-warnning: ' Date +%y '-'%m '-'%d '%H ': '%m ': '%s ', disk $item7\t is out of space, please handle!! ' >> $LOG _file
Else
echo "\t\t\t\t disk space $item7\t\t using normal!!" >> $LOG _file
Fi
Done
#
# Check the IO of the disk for monitoring, Iostat
#
echo >> $LOG _file
echo >> $LOG _file
echo "***************************************** check iostat *****************************************" >>$ Log_file
Iostat 1 3 >> $LOG _file
#
# Monitor network traffic, where you can make a list of hosts and Ping each host to see if the network is connected.
#
echo >> $LOG _file
echo >> $LOG _file
echo "***************************************** check netstat *****************************************" >>$ Log_file
Netstat-i >> $LOG _file
#
# Check the alarm log of the host
#
echo >> $LOG _file
echo >> $LOG _file
echo "***************************************** Check system err *****************************************" >> $LOG _file
Errpt | head-10 >> $LOG _file
day= ' Date +%d | Awk-f "/" ' {Print $1$2} '
Errpt | awk ' {print $} ' | grep ^ $day
If [$?-eq 0]; Then
echo "log-warnning: ' Date +%y '-'%m '-'%d ' '%H ': '%m ': '%s ', the system has found a error today. Please check the error
">> $LOG _file
Else
echo >> $LOG _file
echo "\t\t\t\t There is no system error. System is ok!! >> $LOG _file
Fi
#
# Check to see if HA is running properly
#
echo >> $LOG _file
echo >> $LOG _file
echo "***************************************** check HACMP status *****************************************" > > $LOG _file
/usr/es/sbin/cluster/clstat-o > $TEMP _path/ha_info
Lssrc-g Cluster >> $TEMP _path/ha_info
Cat $TEMP _path/ha_info >> $LOG _file
echo >> $LOG _file
Cat $TEMP _path/ha_info| grep Node: ' |awk-f ': ' {print $2,$3} ' | awk ' {print $1,$3} ' | While Read line
Todo
node=$ (echo $line | awk ' {print} ') "' s"
echo $line |grep up$ >/dev/null
If ["$?"-eq 0]; Then
echo "\t\t\t\t the node $node is ok!!" >> $LOG _file
Else
echo "' Date +%y '-'%m '-'%d '%H ': '%m ': '%s ', log-warnning:the node $node status is down, it was terminated."
>> $LOG _file
Fi
Done
#
# Check that the main 6 processes of the database are normal.
#
echo >> $LOG _file
echo >> $LOG _file
echo "***************************************** Check Oracle process *****************************************" > > $LOG _file
Ps-ef | grep Ora_ | Grep-v grep | Awk-f '-' ' {print $} ' | awk ' {print $} ' >/$TEMP _path/ora_process_info
Ps-ef | grep Ora_ | grep-v grep >> $LOG _file
# Background Process Ckpt
If [' grep ora_ckpt_ora92 $TEMP _path/ora_process_info ']; Then
Count=1
Else
Echo ' log-warnning: ' Date +%y '-'%m '-'%d '%H ': '%m ': '%s ', the Process ora_ckpt_ora92 was terminated! ' >> $LOG _file
Fi
# Background Process DBWR
If [' grep ora_dbw0_ora92 $TEMP _path/ora_process_info ']; Then
count=$ ((count+1))
Else
echo "log-warnning: ' Date +%y '-'%m '-'%d ' '%H ': '%m ': '%s ', the Process ora_dbw0_ora92 was terminated!" >> $LOG _file
Fi
# Background Process Reco
If [' grep ora_reco_ora92 $TEMP _path/ora_process_info ']; Then
count=$ ((count+1))
Else
echo "log-warnning: ' Date +%y '-'%m '-'%d ' '%H ': '%m ': '%s ', the Process ora_reco_ora92 was terminated!" >> $LOG _file
Fi
# Background Process LGWR
If [' grep ora_lgwr_ora92 $TEMP _path/ora_process_info ']; Then
count=$ ((count+1))
Else
echo "log-warnning: ' Date +%y '-'%m '-'%d ' '%H ': '%m ': '%s ', the Process ora_lgwr_ora92 was terminated!" >> $LOG _file
Fi
# Background Process Pmon
If [' grep ora_pmon_ora92 $TEMP _path/ora_process_info ']; Then
count=$ ((count+1))
Else
echo "log-warnning: ' Date +%y '-'%m '-'%d ' '%H ': '%m ': '%s ', the Process ora_pmon_ora92 was terminated!" >> $LOG _file
Fi
# Background Process Smon
If [' grep ora_smon_ora92 $TEMP _path/ora_process_info ']; Then
count=$ ((count+1))
Else
echo "log-warnning: ' Date +%y '-'%m '-'%d ' '%H ': '%m ': '%s ', the Process ora_smon_ora92 was terminated!" >> $LOG _file
Fi
If ["$COUNT"-eq 6];then
echo >> $LOG _file
echo "\t\t\t\tthe main six Oracle processes is OK!!" >> $LOG _file
Else
:
Fi
#
# Check The Oracle tablespace.
#
echo >> $LOG _file
echo >> $LOG _file
echo "***************************************** check Oracle tablespace *****************************************" >> $LOG _file
#su-oracle-c sqlplus Dxh/dxh Sqlplus-s xxx/xxx <<! EOF > $TEMP _path/ts_info
Set PageSize 100
Set Linesize 100
Col status for A10
Col Tablespace_name for A20
Col contents for A10
Col "Size (M)" for A15
Col used for A15
Col pct for A10
Select D.status, D.tablespace_name,
To_char (NVL (a.bytes/1024/1024, 0), ' 99g999g990 ') "Size (M)",
To_char (NVL (A.BYTES-NVL (f.bytes, 0), 0)/1024/1024, ' 99g999g990d00 ') used,
To_char (NVL (A.BYTES-NVL (f.bytes, 0))/a.bytes *, 0), ' 990d00 ') | % ' pct
From Sys.dba_tablespaces D,
(select Tablespace_name, sum (bytes) bytes from Dba_data_files Group by Tablespace_name) A,
(select Tablespace_name, sum (bytes) bytes from Dba_free_space Group by Tablespace_name) F
WHERE D.tablespace_name = a.tablespace_name (+)
and D.tablespace_name = F.tablespace_name (+)
Order BY Tablespace_name;
Exit
! Eof
Cat $TEMP _path/ts_info>> $LOG _file
Cat $TEMP _path/ts_info |grep ONLINE |awk ' {print $ ': "$": "$": "$}" |while Read line
Todo
ts_name=$ (Echo $line |awk-f ': ' {print $} ')
ts_total=$ (Echo $line |awk-f ': ' {print $} ')
ts_used=$ (Echo $line |awk-f ': ' {print $} ')
ts_used_pct=$ (Echo $line |awk-f ': ' {print $} ' |awk-f '% ' {print} ' |awk-f '. ') ' {print '} ')
If ["$ts _used_pct"-gt "$TS _value"-O "$ts _used_pct"-eq "$TS _value"]; Then
echo "log-warnning: ' Date +%y '-'%m '-'%d '%H ': '%m ': '%s ', table space $ts_name The remaining space is tight, please clean up the table space as soon as possible!" >> $LOG _file
Else
echo "\t\t\t\t the tablespace of $ts _name\t is ok!!" >> $LOG _file
Fi
Done
#
# Check The Oracle Job.
#
echo >> $LOG _file
echo >> $LOG _file
echo "***************************************** check Oracle Job *****************************************" >> $LOG _file
Sqlplus-s xxx/xxx <<!! ET >> $LOG _file
Col Job for 999
Col Last_date for A20
Col Next_date for A20
Col What for A40
Set Linesize 120
Select Job,what,
To_char (last_date, ' yyyy-mm-dd hh24:mi:ss ') last_date,
To_char (next_date, ' yyyy-mm-dd hh24:mi:ss ') next_date,
Failures
From Dba_jobs
Order BY Job;
!! Et
Sqlplus-s xxx/xxx <<! EOF > $TEMP _path/job_info
Col Flag for A5
Col Rou for 99999
Select ' XXX ' Flag,job,failures,broken,round (next_date-sysdate,2) *100 Rou from Dba_jobs order by job;
! Eof
Cat $TEMP _path/job_info |grep XXX |awk ' {print $2,$3,$4,$5} ' |while read line
Todo
Jobnum= ' echo $line | awk ' {print '} '
Failure= ' echo $line | awk ' {print $} '
Broken= ' echo $line | awk ' {print $} '
Round= ' echo $line | awk ' {print $} '
If ["$jobnum"-eq 3-o "$jobnum"-eq 4]; Then
If ["$failure"-eq 0-a "$broken" = "N"-A "$round"-le 100]; Then
echo "\t\t\t\tthe Job $jobnum is ok!!" >> $LOG _file
Else
echo "log-warnning: ' Date +%y '-'%m '-'%d '%H ': '%m ': '%s ', the Job $jobnum was terminated!" >> $LOG _file
Fi
Else
If ["$failure"-eq 0-a "$broken" = "N"-A "$round"-eq 0]; Then
echo "\t\t\t\tthe Job $jobnum is ok!!" >> $LOG _file
Else
echo "log-warnning: ' Date +%y '-'%m '-'%d '%H ': '%m ': '%s ', the Job $jobnum was terminated!" >> $LOG _file
Fi
Fi
Done
#
# Check Oracle Alert log.
#
echo >> $LOG _file
echo >> $LOG _file
echo "***************************************** check Oracle Alert log *****************************************" >> $LOG _file
tail-300 $ORACLE _base/admin/ora92/bdump/alert_ora92.log | Grep-v Thread | \
Grep-v Current | Grep-v "' Date + '%a%h '" | Grep-v ": [0-9][0-9]:" >> $LOG _file