diff --git a/vjdump/vjdump.sh b/vjdump/vjdump.sh index 22dbc9a2..5a0f8a06 100755 --- a/vjdump/vjdump.sh +++ b/vjdump/vjdump.sh @@ -39,19 +39,12 @@ START() fi # try to find $JAVA_HOME if not set - if [[ -z ${JAVA_HOME} || ! -d ${JAVA_HOME} ]]; then - JAVA_HOME_CANDIDATES=$(ps aux \ - | grep java \ - | awk '{print $11}' \ - | sed -n 's/\/bin\/java$//p') - for JAVA_HOME_TEMP in ${JAVA_HOME_CANDIDATES[@]}; do - if [ -f ${JAVA_HOME_TEMP}/lib/tools.jar ]; then - JAVA_HOME=${JAVA_HOME_TEMP} - break - fi - done + if [ -z "$JAVA_HOME" ] ; then + JAVA_HOME=`readlink -f \`which java 2>/dev/null\` 2>/dev/null | \ + sed 's/\jre\/bin\/java//' | sed 's/\/bin\/java//'` fi - if [ -z ${JAVA_HOME} ]; then + + if [ ! -f "$JAVA_HOME/bin/jstack" ] ; then echo -e "\033[31m\$JAVA_HOME not found. please export JAVA_HOME manually.\033[0m" exit -1 fi @@ -70,8 +63,7 @@ START() JSTACK_LOG=${LOGDIR}/jstack-${PID}-${DATE}.log ${JAVA_HOME}/bin/jstack -l $PID > ${JSTACK_LOG} if [[ $? != 0 ]]; then - echo -e "\033[31mprocess jstack error, now exit.\033[0m" - exit -1 + echo -e "\033[31mprocess jstack error.\033[0m" fi echo -e "$(date '+%Y-%m-%d %H:%M:%S') Finish to process jstack." sleep ${SLEEP_TIME} @@ -86,8 +78,7 @@ START() VJTOP_LOG=${LOGDIR}/vjtop-${PID}-${DATE}.log $VJTOP_SCRIPT -n 1 -d $VJTOP_DURATION $PID > ${VJTOP_LOG} if [[ $? != 0 ]]; then - echo -e "\033[31mprocess vjtop error, now exit.\033[0m" - exit -1 + echo -e "\033[31mprocess vjtop error.\033[0m" fi echo -e "$(date '+%Y-%m-%d %H:%M:%S') Finish to process vjtop." else @@ -97,8 +88,7 @@ START() JINFO_FLAGS_LOG=${LOGDIR}/jinfo-flags-${PID}-${DATE}.log ${JAVA_HOME}/bin/jinfo -flags $PID 1>${JINFO_FLAGS_LOG} 2>&1 if [[ $? != 0 ]]; then - echo -e "\033[31mprocess jinfo -flags error, now exit.\033[0m" - exit -1 + echo -e "\033[31mprocess jinfo -flags error.\033[0m" fi echo -e "$(date '+%Y-%m-%d %H:%M:%S') Finish to process jinfo -flags." @@ -107,8 +97,7 @@ START() JMAP_HEAP_LOG=${LOGDIR}/jmap_heap-${PID}-${DATE}.log ${JAVA_HOME}/bin/jmap -heap $PID > ${JMAP_HEAP_LOG} if [[ $? != 0 ]]; then - echo -e "\033[31mprocess jmap -heap error, now exit.\033[0m" - exit -1 + echo -e "\033[31mprocess jmap -heap error.\033[0m" fi echo -e "$(date '+%Y-%m-%d %H:%M:%S') Finish to process jmap -heap." fi @@ -118,8 +107,7 @@ START() JMAP_HISTO_LOG=${LOGDIR}/jmap_histo-${PID}-${DATE}.log ${JAVA_HOME}/bin/jmap -histo $PID > ${JMAP_HISTO_LOG} if [[ $? != 0 ]]; then - echo -e "\033[31mprocess jmap -histo error, now exit.\033[0m" - exit -1 + echo -e "\033[31mprocess jmap -histo error.\033[0m" fi echo -e "$(date '+%Y-%m-%d %H:%M:%S') Finish to process jmap -histo." sleep ${SLEEP_TIME} @@ -129,8 +117,7 @@ START() JMAP_HISTO_LIVE_LOG=${LOGDIR}/jmap_histo_live-${PID}-${DATE}.log ${JAVA_HOME}/bin/jmap -histo:live $PID > ${JMAP_HISTO_LIVE_LOG} if [[ $? != 0 ]]; then - echo -e "\033[31mprocess jmap -histo:live error, now exit.\033[0m" - exit -1 + echo -e "\033[31mprocess jmap -histo:live error.\033[0m" fi echo -e "$(date '+%Y-%m-%d %H:%M:%S') Finish to process jmap -histo:live." sleep ${SLEEP_TIME} @@ -141,8 +128,7 @@ START() echo -e "$(date '+%Y-%m-%d %H:%M:%S') Begin to process jmap -dump:live." ${JAVA_HOME}/bin/jmap -dump:live,format=b,file=${JMAP_DUMP_FILE} $PID if [[ $? != 0 ]]; then - echo -e "\033[31mprocess jmap -dump:live error, now exit.\033[0m" - exit -1 + echo -e "\033[31mprocess jmap -dump:live error.\033[0m" fi echo -e "$(date '+%Y-%m-%d %H:%M:%S') Finish to process jmap -dump:live." @@ -159,8 +145,7 @@ START() # "\cp" means unalias cp, it can cover files without prompting \cp -rf $GCLOG ${LOGDIR}/ if [[ $? != 0 ]]; then - echo -e "copy gc log error, now exit." - exit -1 + echo -e "copy gc log error." fi fi echo -e "$(date '+%Y-%m-%d %H:%M:%S') Finish to process gc log." @@ -174,8 +159,7 @@ START() ZIP_FILE=${BASEDIR}/vjdump-${PID}-${DATE}.zip zip -j ${ZIP_FILE} ${LOGDIR}/*.log if [[ $? != 0 ]]; then - echo -e "\033[31mzip files error, exit.\033[0m" - exit -1 + echo -e "\033[31mzip files error.\033[0m" else echo -e "zip files success, the zip file is \033[34m${ZIP_FILE}\033[0m" fi @@ -187,8 +171,7 @@ START() ZIP_FILE_WITH_HEAP_DUMP=${BASEDIR}/vjdump-with-heap-${PID}-${DATE}.zip zip -j ${ZIP_FILE_WITH_HEAP_DUMP} ${LOGDIR}/*.log ${JMAP_DUMP_FILE} if [[ $? != 0 ]]; then - echo -e "\033[31mzip files which include dump file error, exit.\033[0m" - exit -1 + echo -e "\033[31mzip files which include dump file error.\033[0m" else echo -e "zip files which include dump file success, the zip path is \033[34m${ZIP_FILE_WITH_HEAP_DUMP}\033[0m" fi