now=`date +%Y%m%d-%H:%M:%S`
currentday=`date +%y%m%d`
WORK_HOME=/data/ispp
LOG_FILE=${WORK_HOME}/log/main.log${currentday}
RECORD_LINE_NUM_FILE=${WORK_HOME}/sh/logLineNum.data
PNAME="ispp"
MonProcessAlive()
{
flag=1
checkprocess=`ps -ef | grep target=$PNAME | grep -v "grep" `
if [ -z "$checkprocess" ] ; then
flag=0
fi
if [ $flag = 0 ]
then
Restart "monPs,restart"
fi
}
MonLogAlive()
{
flag=1
if [ ! -f $RECORD_LINE_NUM_FILE ]
then
touch $RECORD_LINE_NUM_FILE
echo "0" > $RECORD_LINE_NUM_FILE
fi
#get log size
lineNum=`ls -l $LOG_FILE |awk '{print $5}'`
recordLineNum=`more $RECORD_LINE_NUM_FILE`
#echo "log lineNum: $lineNum"
#echo "record lineNum: $recordLineNum"
if [ "$lineNum" = "$recordLineNum" ]
then
flag=0
else
echo $lineNum > $RECORD_LINE_NUM_FILE
fi
if [ $flag = 0 ]
then
Restart "monLog,restart"
fi
}
MonPort()
{
pid=`netstat -an |grep 9998 |grep LISTEN`
if [ "$pid" = "" ]
then
Restart "MonPort,restart"
fi
}
Restart()
{
msg=`hostname`,$PNAME,`date +%Y%m%d%H%M%S`,$1
sh $WORK_HOME/sh/start.sh
#sh $WORK_HOME/sh/sendmail.sh $msg
echo "$msg" >> $WORK_HOME/sh/monitor.log
}
MonTelnetPort()
{
LANG=C;export LANG;
IP=$1
PORT=$2
ret=`(echo "ls";sleep 2)|telnet $IP $PORT`
flag=`echo "$ret"|egrep "HTTP|Jetty" |wc -l`
if [ $flag -le 0 ]
then
Restart
fi
}
MonProcessAlive
MonTelnetPort 127.0.0.1 9998
shell脚本监控
最新推荐文章于 2024-08-26 22:48:44 发布