输入tomcat应用日志文件路径,脚本根据日志文件路径生成3个脚本:captureKeyWord.sh(过滤实时日志关键字),grepKeyWord.sh(抓取已生成日志中查询关键字),restartApp.sh(重启tomcat应用)
## 应用日志路径如:/home/wy/www/应用名/logs/catalina.out,或/export/Domains/应用名/server1/logs/catalina.out
SH1="captureKeyWord.sh" ## 实时抓取关键字
SH2="grepKeyWord.sh" ## 抓取已生成日志关键中关键字
SH3="restartApp.sh" ## 重启tomcat脚本
# set -x
usage() {
echo "Usage: `basename $0` + Log_File_Path"
exit -1
}
getAppInfo() {
echo $1 | awk -F'/' '{if ("export"==$2 && "Domains"==$3) {print $4 " export"} else if("home"==$2 && "wy"==$3 && "www"==$4){print $5 " home"} else {print ""}}'
}
if [ $# -lt 1 ];then
usage
fi
LOG=$1
APPINFO=`getAppInfo $LOG`
[ -z $APPINFO ] && echo "[ERROR]: Log_File_Path incorrect, please check!" && usage
APPNAME=`echo $APPINFO | cut -d' ' -f1`
APPTYPE=`echo $APPINFO | cut -d' ' -f2`
RESTCMD=""
case $APPTYPE in ## 根据应用部署路径,判断重启脚本位置
"export")
RESTCMD="sudo /export/Domains/$APPNAME/server1/bin/stop.sh;sudo /export/Domains/$APPNAME/server1/bin/start.sh"
;;
"home")
RESTCMD="sudo /home/wy/tools/bin/resttart.sh /home/wy/www/$APPNAME"
;;
*)
echo "[EROOR]: unknow applicaiton type!"
usage
;;
esac
## 拼装脚本字符串,塞进脚本文件
echo "tail -200f $LOG | grep --color -20 \"\$1\"">$SH1
echo "grep --color -20 \"\$1\" $LOG">$SH2
echo "$RESTCMD"> $SH3
chmod +x $SH1 $SH2 $SH3