#Here is the script
DataPath=/backup/performance/data
ReportDIR=/data/workshop/report
ScriptDIR=/data/workshop/scripts
TIME=`date +%H`
cd ${ScriptDIR}
if [ $USER != 'root' ]
then
clear
echo '\n\n\n\n'
echo ' Please login root run this script'
echo '\n\n\n\n'
exit
fi
if [ $TIME -eq 16 ]
then
# Check filesystem utilization
df -k > ${DataPath}/df-`hostname`.`date '+%m%d%H%M'`
#
# Check process status
#
echo "There are total `ps -ef| wc -l | awk '{print $1}'` processes in system now." >> ${ScriptDIR}/report.txt
echo " " >> ${ScriptDIR}/report.txt
echo " " >> ${ScriptDIR}/report.txt
# Check top 10 process
echo "Top 10 process at `date` " >> ${ScriptDIR}/report.txt
echo " " >> ${ScriptDIR}/report.txt
ps ug | egrep -v "CPU|kproc" | sort +2b -3 -n -r \
| head -n 10 >> ${ScriptDIR}/report.txt
echo " " >> ${ScriptDIR}/report.txt
echo " " >> ${ScriptDIR}/report.txt
# Check online userID
echo " " >> ${ScriptDIR}/report.txt
echo "Online userID at `date`" >> ${ScriptDIR}/report.txt
echo " " >> ${ScriptDIR}/report.txt
who -u >> ${ScriptDIR}/report.txt
echo " " >> ${ScriptDIR}/report.txt
echo " " >> ${ScriptDIR}/report.txt
#
# Compress files
#
for i in `cat ${ScriptDIR}/compress.lst`
do
cd $i
find . ! -name "*.Z" -mtime +1 |xargs -I{} compress {} 2>/dev/null
done
cd ${ScriptDIR}
mail -s "`hostname` system status report `date` " abc@abc.com < ${ScriptDIR}/report.txt
# Rename ${ScriptDIR}/report.txt
mv ${ScriptDIR}/report.txt ${ReportDIR}/report.txt.`date +%m%d`
chown batch:qad ${ReportDIR}/report.txt.`date +%m%d`
fi
#
# Check flag file.
#
for i in /u/batch/mfgp/reserve
do
if [ -f $RESDIR/*session* ]
then
echo "Attention! there is a session still running in $i" >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/sendmail.flag
fi
done
#Check system defunct process
ps -ef | grep defunct | grep -v grep | sort -u > ${ScriptDIR}/defunct-new.txt
i=`diff ${ScriptDIR}/defunct-new.txt ${ScriptDIR}/defunct-old.txt | grep "<" |wc -l|awk '{print $1}'`
if (( $i > 0 ))
then
echo " " >> ${ScriptDIR}/warning.txt
echo "Warning!!!, system have new defunct process, please check it carefully!!!" >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
ps -ef|grep defunct | grep -v grep >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/sendmail.flag
mv ${ScriptDIR}/defunct-new.txt ${ScriptDIR}/defunct-old.txt
fi
for i in `cat ${ScriptDIR}/process.lst`
do
ps -ef|grep $i | grep -v grep > /dev/null
if [ $? -eq 1 ]
then
echo " " >> ${ScriptDIR}/sendmail.flag
echo "Attention!!!, $i does not run." >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
fi
done
# Check file system space
flag=`df -k | awk '{if($4>97) print $0}'|wc -l`
if [ $flag -gt 0 ]
then
echo " " >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
echo "Space utilization over 90% :" >> ${ScriptDIR}/warning.txt
df -k | head -1 >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/sendmail.flag
df -k | awk '{if($4>90) print $0}' >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
fi
# system utilization summery
grep 0 $DataPath/vmstat.????.`date +%m%d%y` | tail -60 > ${ScriptDIR}/vmstattemp
line=`awk 'BEGIN {A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;I=0;J=0};
{A=$6;B=$7;C=$14+$15;D=$2;E=$17};
A >=1 {F+=1};
B >=1 {G+=1};
C >=70 {H+=1};
E >=30 {I+=1};
D >J {J=D};
END {print NR,F,G,H,I,J}' ${ScriptDIR}/vmstattemp`
flag1=`echo $line | awk '{if($2>20) print $0}' | wc -l`
flag2=`echo $line | awk '{if($3>20) print $0}' | wc -l`
flag3=`echo $line | awk '{if($4>40) print $0}' | wc -l`
flag4=`echo $line | awk '{if($5>40) print $0}' | wc -l`
flag5=`echo $line | awk '{if($6>20) print $0}' | wc -l`
if [[ ${flag1} -gt 0 || ${flag2} -gt 0 || ${flag3} -gt 0 || ${flag4} -gt 0 || ${flag5} -gt 0 ]]
then
echo " " >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/sendmail.flag
echo "Warnning! System is busy now, please check" >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
head -1 ${ScriptDIR}/title-sys.txt | awk '{printf "%10s %10s %10s %10s %10s %10s\n",$1,$2,$3,$4,$5,$6}' >> ${ScriptDIR}/warning.txt
echo $line | awk '{printf "%10s %10s %10s %10s %10s %10s\n",$1,$2,$3,$4,$5,$6}' >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
cat readme.txt >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
fi
rm ${ScriptDIR}/vmstattemp
errpt > ${ScriptDIR}/errpt.new
if [ `diff ${ScriptDIR}/errpt.new ${ScriptDIR}/errpt.old | wc -l | awk '{print $1}'` -gt 0 ]
then
echo "System error report:" >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
errpt >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/sendmail.flag
fi
errpt > ${ScriptDIR}/errpt.old
# Check system faild login
who -s /etc/security/failedlogin > failedlogin.new
if [ `diff ${ScriptDIR}/failedlogin.new ${ScriptDIR}/failedlogin.old | wc -l | awk '{print $1}'` -gt 0 ]
then
echo "As below is faild login record in `date +%h%y`" >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
diff ${ScriptDIR}/failedlogin.new ${ScriptDIR}/failedlogin.old | grep "<" | cut -d" " -f2- >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/warning.txt
echo " " >> ${ScriptDIR}/sendmail.flag
fi
mv ${ScriptDIR}/failedlogin.new ${ScriptDIR}/failedlogin.old
chown batch:qad ${ScriptDIR}/failedlogin.old
if [ -f ${ScriptDIR}/sendmail.flag ]
then
mail -s "`hostname` system warning report `date` " abc@abc.com < warning.txt
rm ${ScriptDIR}/sendmail.flag
cat ${ScriptDIR}/warning.txt >> ${ReportDIR}/warning.txt.`date +%m%d`
chown batch:qad ${ReportDIR}/warning.txt.`date +%m%d`
rm ${ScriptDIR}/warning.txt
fi
--
Best Regards!
Hello, I am Nikolai NG, come from Carton, China. I love here.