#!/bin/bash

#list the parameters of the linux system
date=`date | awk '{print $2 "-" $3 "-" $4}'`
{
echo '                          ######who has logon the system---"who" command######'
who
echo '                          ######running tomcat number,http status,open*** status######'
echo running tomcat number:`ps aux |grep tomcat[1,2] |grep -v "grep tomcat[1,2]" | wc -l`
service httpd status
echo open***:`ps aux | grep open*** | grep -v "grep open***"`
##service heartbeat status
echo '                          ######check any modified or new files at route /etc today######'
ls -Rl /etc | grep "`date | awk '{print $2,$3}'`"
echo '                          ######the tomcat[1,2] files space######'
du -sh /usr/local/tomcat[1,2]
echo '                          ######check the http error message######'
tail -10 /etc/httpd/logs/error_log | grep "`date | awk '{print $2,$3}'`"
echo '                          ######CPU%  Apache-memory  Tomcat-memory######'
echo CPU%:`ps aux | awk '{print $3}' |awk 'BEGIN{sum=0}{sum+=$1}END{print sum}'`% " "Apache-memory:`ps aux | grep httpd | grep -v "grep httpd" |awk '{print $6}' |awk 'BEGIN{sum1=0}{sum1+=$1}END{print sum1/1024}'`M " "TOMCAT-memory:`ps aux | grep java | grep -v "grep java" |awk '{print $6}' |awk 'BEGIN{sum2=0}{sum2+=$1}END{print sum2/1024}'`M
echo '                          ######PID infomation---"ps u" command######'
ps u
echo '                          ###### memory state---"free -m df -h" command######'
free -m
df -h
echo '                          ######vmstat state in every 5 secends---"vmstat 5 5" command######'
vmstat 5 5
echo '                          ######the i/o port state of the disk---"iostat -d -k" command######'
iostat -d -k |  sed '/^$/d'
echo '                          ######cpu infomation---"cat /proc/stat"######'
cat /proc/stat
echo '                          ######the avarage of the cpu parameters---"mpstat" command######'
mpstat | sed '/^$/d'
echo '                          ######system load in unit time---"uptime" command######'
uptime
echo '                          ######netstat---"netstat" command######'
netstat -nat|grep tcp |awk '{print $NF}'|sort|uniq -c|sort -n
#echo '------net infomation pachage analyse---"tcpdump" command------'
#tcpdump -i 1 -c 20 -a
echo '                          ######system status---"sar -w -u -b -R -d -v 3 1" command######'
sar -w  -u -b -R -d -v  3 1  | sed '/^$/d'
echo '                          ######tomcat1/2 exception######'
cat /usr/local/tomcat[1,2]/logs/catalina.`date +%Y-%m-%d`.log 2>/dev/null| grep  Exception | tail -10
echo '                          ######the latest 5 failure users who logon the system######'
lastb | head -5
} > /opt/systemstate/$date
mail -s "Web system status" jxwpx@163.com </opt/systemstate/$date