#!/bin/bash
export
LC_ALL=zh_CN.UTF-8
SERVER_NAME=
"趣驾云接口服务"
URL_2=
"http://127.0.0.1/get_rss_news?p=%7b%27chId%27:%27TIYU%27%7d"
KeyWorld_2=
'<title>'
URL_3=
"http://127.0.0.1/get_json_weather?p=%7blon:116.407617,lat:39.993956,date:1%7d"
KeyWorld_3=
'temperature'
mail_ary=(
xxxxxxxxx@navinfo.com
xxxxxxxxx@navinfo.com
xxxxxxxxx@navinfo.com
)
function
doFail(){
local
ipinfo=$(
ifconfig
|
sed
-n
'2p'
|
awk
'{print substr($2,6)}'
);
for
_v
in
${mail_ary[*]} ;
do
echo
"[$SERVER_NAME 异常] - [$(date -d "
0 min
" +"
%Y-%m-%d %H:%M:%S
")] - [请求地址: $1] - [请求返回码: $2]"
| mail -s ${ipinfo}服务异常 ${_v}
done
echo
"[ERROR] - [$(date -d "
0 min
" +"
%Y-%m-%d %H:%M:%S
")] - 返回码[$2] - 重启Tomcat服务"
>> detect-http.log
sh
/home/opentsp/crontab/ibr-shutdown
.sh
exit
;
}
TIME_OUT=40
function
doCheck(){
local
URL_X=$1;
local
KeyWorld_X=$2;
HTTP_STATUS_CODE=`curl -m $TIME_OUT -o
/dev/null
-s -w
"%{http_code}"
"${URL_X}"
`
if
[ $HTTP_STATUS_CODE != 200 ];
then
echo
"-> Fail - 返回码${HTTP_STATUS_CODE}"
;
doFail ${URL_X} ${HTTP_STATUS_CODE};
else
if
curl -m ${TIME_OUT} -s ${URL_X} |
grep
-q ${KeyWorld_X};
then
echo
"-> SUCCESS"
;
else
echo
"->> Fail"
;
doFail ${URL_X} ${HTTP_STATUS_CODE};
fi
fi
}
doCheck ${URL_2} ${KeyWorld_2}
doCheck ${URL_3} ${KeyWorld_3}