#!/bin/sh
date=`date +"%Y-%m-%d-%H:%M"`
title="api Running state "
contentFail="Abnormal running state:"
contentSuccess="status is ok:"
url="http://192.168.1.87:3399"
status=`curl -m 20 -s -I $url | grep HTTP | awk '{print $2}'`
java_pid=$(jps|grep HshServer|awk '{print $1}')
cd /sh
laststatus=`cat status.log`
if [ "$status" == "200" ]
then
if [ "$laststatus" != 200 ]
then
echo "200" > status.log
fi
else
if [ "$laststatus" == 200 ]
then
/usr/bin/netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' >> /sh/tcplinking
echo "主机: XX 服务: api 说明: XX主机api服务已经停止运行.... 2分钟后尝试重新启动....." |mail -s "87 api服务停止运行" XXXX@qq.com
cat /sh/tcplinking |mail -s "xx api停止运行" XXXXXXXX@qq.com
/usr/bin/python /sh/mail.py "$title" "$contentFail $url $date $status"
echo "$status" > status.log
# jmap -dump:format=b,file=/sh/dump/hshserver_$date.dump "$java_pid"
/bin/sh /sh/restart.sh
fi
fi