#!/bin/sh

echo " - time interval (0: once) ? "
read TERM

while [ 1 ]
do
    echo "      "
    echo "                >>>  " `hostname` " Server Report  <<<"
    echo "                =============================================="
    echo "      "

    CUR_DATE=`date +"%Y_%m_%d %H:%M:%S"`
    echo  "# Tomcat/MariaDB/Radius (" $CUR_DATE ") : "
    M0=`ps -ef|grep java | grep -v grep | wc -l`
    echo " Tomcat ----------------> [ $M0 ]"

    M0=`ps -ef|grep -v grep | grep mariadbd | wc -l`
    echo " MariaDB ---------------> [ $M0 ]"

    M0=`ps -ef|grep radiusd | grep -v grep | wc -l`
    echo " radiusd ---------------> [ $M0 ]"
    echo "      "

    echo  "# Port status : "
    I2=`netstat -an|grep 8080 |grep ESTABLISHED |wc -l`
    echo " ESTABLISHED(8080) -----> [" $I2 "]"
    I2=`netstat -an|grep 3306 |grep ESTABLISHED |wc -l`
    echo "            (3306) -----> [" $I2 "]"
    I2=`netstat -an|egrep "1812|1813" |grep ESTABLISHED |wc -l`
    echo "            (1812) -----> [" $I2 "]"
    I2=`netstat -an|egrep -v "8080|3306|1812|1813" |grep ESTABLISHED |wc -l`
    echo "            (Etc ) -----> [" $I2 "]"
    I2=`netstat -an|grep ESTABLISHED |wc -l`
    echo "            (Total)-----> [" $I2 "]"

    I4=`netstat -an|grep 8080 |grep TIME_WAIT |wc -l`
    echo " TIME_WAIT  (8080) -----> [" $I4 "]"
    I4=`netstat -an|grep 3306 |grep TIME_WAIT |wc -l`
    echo "            (3306) -----> [" $I4 "]"
    I4=`netstat -an|egrep "1812|1813" |grep TIME_WAIT |wc -l`
    echo "            (1812) -----> [" $I4 "]"
    I4=`netstat -an|egrep -v "8080|3306|1812|1813" |grep TIME_WAIT |wc -l`
    echo "            (Etc ) -----> [" $I4 "]"
    I4=`netstat -an|grep TIME_WAIT |wc -l`
    echo "            (Total)-----> [" $I4 "]"

    I6=`netstat -an|grep 8080 |grep FIN_WAIT_2 |wc -l`
    echo " FIN_WAIT   (8080) -----> [" $I6 "]"
    I6=`netstat -an|grep 3306 |grep FIN_WAIT_2 |wc -l`
    echo "            (3306) -----> [" $I6 "]"
    I6=`netstat -an|egrep "1812|1813" |grep FIN_WAIT_2 |wc -l`
    echo "            (1812) -----> [" $I6 "]"
    I6=`netstat -an|egrep -v "8080|3306|1812|1813" |grep FIN_WAIT_2 |wc -l`
    echo "            (Etc ) -----> [" $I6 "]"
    I6=`netstat -an|grep FIN_WAIT_2 |wc -l`
    echo "            (Total)-----> [" $I6 "]"

    I8=`netstat -an|grep 8080 |grep CLOSE_WAIT |wc -l`
    echo " CLOSE_WAIT (8080) -----> [" $I8 "]"
    I8=`netstat -an|grep 3306 |grep CLOSE_WAIT |wc -l`
    echo "            (3306) -----> [" $I8 "]"
    I8=`netstat -an|egrep "1812|1813" |grep CLOSE_WAIT |wc -l`
    echo "            (1812) -----> [" $I8 "]"
    I8=`netstat -an|egrep -v "8080|3306|1812|1813" |grep CLOSE_WAIT |wc -l`
    echo "            (Etc ) -----> [" $I8 "]"
    I8=`netstat -an|grep CLOSE_WAIT |wc -l`
    echo "            (Total)-----> [" $I8 "]"
    echo "      "

    sleep 2

    echo  "# Process status : "
    ps -o 'user group pid ppid pcpu pmem rss time stime tty args' | grep -v checkport.sh | grep -v pid | grep -v bash
    echo "      "

#    echo  "# CPU status : "
#    sar -P ALL 1
#    echo "      "

    echo  "# CPU status : "
    vmstat 1 2
    echo "      "

    echo  "# Memory status : "
    free
    echo "      "

    sleep 2

    echo  "# Disk status : "
    df -k
    echo "      "

#    echo  "# Table space : "
#    sh /home/util/tablespace.sh

    if [ $TERM -eq 0 ]
    then
        echo
        echo "Press 'Enter' Key to continue ...\c"
        read cmd
        exit
    fi
    sleep $TERM
done


