#!/bin/bash source /etc/profile APPLICATIONS_HOME="/opt/cpic_analy" APPLICATION_NAME="MerchantClient.jar" SNAME=`basename $APPLICATION_NAME .jar` LOG_DIR="$APPLICATIONS_HOME/logs/$SNAME/" STR_LOG=$(date +'%Y-%m-%d_%H-%M') STR_DAY=$(date +'%Y-%m-%d') STR_BEGIN=$(date +'%Y-%m-%d %H:%M:%S') PID=$$ NAME=`basename $0` if [ ! -d ${LOG_DIR} ]; then mkdir -p ${LOG_DIR} fi if [ $(ps -ef|awk -v p=$PID -v n=${NAME} '$2!=p && $NF~n'|wc -c) -gt 200 ]; then echo ${STR_BEGIN}" ${SNAME} is already running,exit!" >> $LOG_DIR/run_${STR_DAY}_sys.log 2>&1 break else echo ${STR_BEGIN}" ${SNAME} begin runing" >> $LOG_DIR/run_${STR_DAY}_sys.log 2>&1 cd ${APPLICATIONS_HOME} $JAVA_HOME/bin/java -jar ${APPLICATIONS_HOME}/${APPLICATION_NAME} >> "${LOG_DIR}/run_${SNAME}_${STR_LOG}.log" 2>&1 STR_END=$(date +'%Y-%m-%d %H:%M:%S') echo ${STR_END}" ${SNAME} end runing" >> $LOG_DIR/run_${STR_DAY}_sys.log 2>&1 fi exit