定时检测jar程序的运行情况

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/bin/bash
####################################################################################
# NOTE:
# The test system is Ubuntu12.04
# This Scripts all rights reserved deserved by MickeyZZC
# Copyright © 2013
#
#2013-09-05:add log_cut
#2013-09-06:optimize code
####################################################################################
PATH="/usr/lib/jvm/java-6-openjdk-amd64/jre/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin"
export $PATH

clear ;
jar_path="/path"
shell_log="/pathlog"
jarexplain_path="/path"
jarsocket_path="/path"

function EXCHANGE(){
	for i in $(cd $jar_path ; echo $1\* )
	do
		java -jar $jar_path/$i &
	done
}

function jar_explain(){
	for i in $(cd $jarexplain_path ; echo *.jar )
	do
		if [ ! -d $i ] ; then
			pid_value=$(ps aux|grep java |grep $i |awk '{print $2}')
			if [ $pid_value ] ; then
				echo $i is $pid_value
			else
				java -jar $jarexplain_path/$i &
				echo "$(date +"%Y%m%d") start $i" >> $shell_log/explain.log
			fi
		fi
	done
}

function jar_socket(){
	pid_value=$(ps aux|grep java |grep "ect_cyl_attendance.jar" |awk '{print $2}')
	if [ $pid_value ] ; then
		echo ect_cyl_attendance.jar is $pid_value
	else
		nohup java -jar $jarsocket_path/ect_cyl_attendance.jar &
		echo "$(date +"%Y%m%d") start ect_cyl_attendance.jar" >> $shell_log/jar_socket.log
	fi
}

function log_cut(){
	for i in $(cd $1 ; echo *.log.*);do
		if [ ${i##*.} != "txt" ] ; then
			cat $1/$i |grep -v "INFO" > $1/$i.txt &&
			rm $1/$i
		fi
	done
	find $1 -name *.txt -type f -size 0 -exec rm {} \;
	find $1 -name *.txt -type f -mtime +7 -exec cat >> $1/logerr.log {} \;
	find $1 -name *.txt -type f -mtime +7 -exec rm {} \;
}

jar_socket &
if [ "01" -le $(date +"%H") -a "12" -ge $(date +"%H") ] ; then
	jar_explain &
	EXCHANGE Exchange_UP
else
	EXCHANGE Exchange_Down &&
	log_cut /var/log/exchange
	log_cut /var/log/ectsocket
fi