<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">crontab 实现定时检测Tomcat进程是否存在,如果不存在则启动Tomcat,如果在此过程中发生任何异常或者错误,则发邮件。</span>
获取Tomcat 进程
function get_tomcat_pid_ps
{
declare NORMALIZED=$(echo $TOMCAT_HOME | tr -s / /)
declare NORMALIZED2=$(readlink -f $TOMCAT_HOME)
declare NORMALIZED3=$(readlink ${NORMALIZED%/})
declare SHELL_NAME="java"
if [ -z $NORMALIZED3 ] ; then
NORMALIZED3 = $NORMALIZED
fi
TOMCAT_PID_FROM_PS=`ps -ef | grep -E "$NORMALIZED|$NORMALIZED2|$NORMALIZED3" \
| grep -v zookeeper | grep -v grep | awk '{print $2 " " $8}' \
| while read line; \
do pid=$(echo $line | awk '{print $1}'); \
fullpath=$(echo $line | awk '{print $2}'); \
if [ $(basename "$fullpath") = "$SHELL_NAME" ]; then echo "$pid" ; fi ; done \
| xargs echo`
if [ $? -ne 0 ]; then
log "ERROR source file:$BASH_SOURCE,line:$LINENO,fun:${FUNCNAME},get tomcat PID failed."
return 1
fi
return 0
}
未完待续……