sh 执行 java cp_shell 脚本调用java进程

#!/bin/sh#Author: cym#2014-05-21#----------------How to use----------------##copy make_java.sh to /bin#chmod +x make_java.sh#monitorAgent_java.sh {start,stop,encode} mainfilename#eg:make_java.sh start test.java#------------------------------------------##JAVA_BIN=/home/admin/jdk1.7.0_55/bin/javaJAVA_BIN=/usr/local/jdk1.7.0_60/bin/java#MAINFILE=$2#MAIN_CLASS="com.cmsz.hostMonitor.rabbitMq.send.HostMonitorDatasMain"MAIN_CLASS="com.cmsz.monitor.agent.CollectAgentMain"path=$(dirname $0)APP_ID=$path"/OMCollectAgent.jar"#echo $APP_ID# return 0 or ppidgetPPID(){program=`ps -ef|grep $APP_ID|grep -v grep`if [ "$program" = "" ]; thenecho "-1"elselocal ppid=$(echo "$program" | awk {'print $2'})echo "$ppid"fi}startConnectionAgent(){echo $APP_IDlocal ppid=$(getPPID)if [ "$ppid" != "-1" ]; thenecho "WARN: $MAIN_CLASS is running!"return 1filocal jarFileLibs="."echo $JAVA_ARGS${JAVA_BIN} -cp $jarFileLibs:/usr/local/OMCollectAgent/lib/*:$APP_ID $MAIN_CLASS $JAVA_ARGSsleep 1ppid2=$(getPPID)echo $ppid2if [ "$ppid2" != "-1" ]; thenecho "INFO: Start $MAIN_CLASS successfully!"return 1elseecho "ERROR: Start $MAIN_CLASS failed! Please check again."return -1fi}stopConnectionAgent(){local ppid=$(getPPID)if [ "$ppid" = "-1" ]; thenecho "INFO: $MAIN_CLASS is not running!"return 0elsekill -9 $ppidsleep 3ppid=$(getPPID)if [ "$ppid" = "-1" ]; thenecho "INFO: Stop $MAIN_CLASS successfully."return 0elseecho "WARN: Could not stop $MAIN_CLASS. Please check again."return -1fifi}usage(){echo "usage:"echo "    $PRG start"echo "    $PRG stop"}#----------------------main----------------------## resolve links - $0 may be a softlinkPRG="$0"JAVA_ARGS="$2"echo $JAVA_ARGSwhile [ -h "$PRG" ]; dols=$(ls -ld "$PRG")link=$(expr "$ls" : '.*-> \(.*\)$')if expr "$link" : '/.*' > /dev/null; thenPRG="$link"elsePRG=$(dirname "$PRG")/"$link"fidoneecho $PRG# Get standard environment variables#PRGDIR=$(dirname "$2")#cd $PRGDIR#echo $PRGDIR#----------compile----------##------------run------------#case "$1" instart)startConnectionAgentexit $?;;stop)stopConnectionAgentexit $?;;*)echo "$1 in usage"usageexit $?;;esac

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值