#!/bin/bash #description: ljdjService export PRG_HOME=/ainmc/work/toptea/dataTransfer PRG_KEYWORD=projectName PRG=$PRG_HOME/server.sh JAVA_HOME=/aa/bb/jdk1.8.0_111 #jdk安装位置 LOGCFG="-Dlogback.configurationFile=$PRG_HOME/conf/logback.xml" FILE_ENCODING="-Dfile.encoding=utf-8" jvmOpt="-Xms2048m -Xmx2048m -XX:PermSize=256M -XX:MaxPermSize=512m" PRG_RUN_USER=nmcuser pidFile=$PRG_HOME/server.pid MAIN_CLASS=com.ai.vv.aa.Main # main方法的路径 jarDir=$PRG_HOME/lib transferType="$2" cd $PRG_HOME function start(){ echo "will start $PRG_KEYWORD $transferType" export CLASSPATH=. for jar in `ls $PRG_HOME/lib/*.jar` do CLASSPATH=$CLASSPATH:$jar done # nohup "$JAVA_HOME"/bin/java -Djobname="$PRG_KEYWORD" -cp "$CLASSPATH" $jvmOpt $LOGCFG $FILE_ENCODING $MAIN_CLASS add "$transferType" >/dev/null 2>&1& "$JAVA_HOME"/bin/java -Djobname="$PRG_KEYWORD" -cp "$CLASSPATH" $jvmOpt $LOGCFG $FILE_ENCODING $MAIN_CLASS add "$transferType" for(( i=1;i<=10;i++));do if [ -e $pidFile ]; then echo "$PRG_KEYWORD is started,pid=`cat $pidFile`" break fi sleep 2 done } function delete(){ echo "will start $PRG_KEYWORD" export CLASSPATH=. for jar in `ls $PRG_HOME/lib/*.jar` do CLASSPATH=$CLASSPATH:$jar done # nohup "$JAVA_HOME"/bin/java -Djobname="$PRG_KEYWORD" -cp "$CLASSPATH" $jvmOpt $LOGCFG $FILE_ENCODING $MAIN_CLASS delete "$transferType">/dev/null 2>&1& "$JAVA_HOME"/bin/java -Djobname="$PRG_KEYWORD" -cp "$CLASSPATH" $jvmOpt $LOGCFG $FILE_ENCODING $MAIN_CLASS delete "$transferType" for(( i=1;i<=10;i++));do if [ -e $pidFile ]; then echo "$PRG_KEYWORD is started,pid=`cat $pidFile`" break fi sleep 2 done } psid=0 checkpid() { javaps=`$JAVA_HOME/bin/jps -l | grep $PRG_KEYWORD` if [ -n "$javaps" ]; then psid=`echo $javaps | awk '{print $1}'` else psid=0 fi } stop() { checkpid if [ $psid -ne 0 ]; then echo -n "Stopping $PRG_KEYWORD ...(pid=$psid) " kill -9 $psid if [ $? -eq 0 ]; then echo "[OK]" else echo "[Failed]" fi checkpid if [ $psid -ne 0 ]; then stop fi else echo "================================" echo "================================" fi } case "$1" in start) if [ -e $pidFile ]; then pid=`cat $pidFile` tpid=`ps -ef | grep java | grep -v grep | grep jobname=$PRG_KEYWORD | grep -c "$PRG_RUN_USER "` if [ $tpid -lt 1 ]; then start else echo "$PRG_KEYWORD already started!! pid="$pid fi else tpid=`ps -ef | grep java | grep -v grep | grep jobname=$PRG_KEYWORD | grep -c "$PRG_RUN_USER "` pid=`ps -ef | grep java | grep -v grep | grep jobname=$PRG_KEYWORD | grep "$PRG_RUN_USER " | awk '{print $2}'` if [ $tpid -lt 1 ]; then start else echo "$PRG_KEYWORD already started!! pid="$pid echo "$pid">server.pid fi fi ;; del) if [ -e $pidFile ]; then pid=`cat $pidFile` tpid=`ps -ef | grep java | grep -v grep | grep jobname=$PRG_KEYWORD | grep -c "$PRG_RUN_USER "` if [ $tpid -lt 1 ]; then delete else echo "$PRG_KEYWORD already started!! pid="$pid fi else tpid=`ps -ef | grep java | grep -v grep | grep jobname=$PRG_KEYWORD | grep -c "$PRG_RUN_USER "` pid=`ps -ef | grep java | grep -v grep | grep jobname=$PRG_KEYWORD | grep "$PRG_RUN_USER " | awk '{print $2}'` if [ $tpid -lt 1 ]; then delete else echo "$PRG_KEYWORD already started!! pid="$pid echo "$pid">server.pid fi fi ;; stop) stop;; *) echo "Usage: server.sh (start|del|stop 工单类型英文关键字)" esac
1. 本站所有资源来源于用户上传和网络,如有侵权请及时联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"mababa.xin",如遇到无法解压的请联系管理员!
码巴巴-优质代码创造者 » linux shell脚本调用java main方法 代码传值
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载完但解压或打开不了?
- 找不到素材资源介绍文章里的示例图片?
- 一个高级程序员模板开发平台