linux批量启动jar包

2021-03-26 03:26

阅读:481

标签:close   查找   开始   open   ima   原因   win   code   else   

先附上命令语句

技术图片技术图片
#!/bin/sh
#当前目录全路径
pp=$(pwd)
export DEMO1=$pp/demo1-8080.jar
export DEMO2=$pp/demo2-8082.jar
 
export DEMO1_port=8080
export DEMO2_port=8082
 
case "$1" in
 
start)
        ## 启动DEMO1
        echo "DEMO1开始启动----------------------"
        echo ‘str:‘$DEMO1‘‘
        nohup java -Xms256m -Xmx256m -jar $DEMO1 1>>./out.log 2>&1 &
        DEMO1_pid=`lsof -i:$DEMO1_port|grep "LISTEN"|awk ‘{print $2}‘`
        until [ -n "$DEMO1_pid" ]
            do
              DEMO1_pid=`lsof -i:$DEMO1_port|grep "LISTEN"|awk ‘{print $2}‘`  
            done
        echo "----------------------DEMO1启动成功pid:$DEMO1_pid"
        
        ## 启动DEMO2
        echo "DEMO2开始启动--------------------------"
        echo ‘str:‘$DEMO2‘‘
        nohup java -Xms256m -Xmx256m -jar $DEMO2 1>>./out.log 2>&1 &
        DEMO2_pid=`lsof -i:$DEMO2_port|grep "LISTEN"|awk ‘{print $2}‘` 
        until [ -n "$DEMO2_pid" ]
            do
              DEMO2_pid=`lsof -i:$DEMO2_port|grep "LISTEN"|awk ‘{print $2}‘`  
            done  
        echo "--------------------------DEMO2启动成功pid:$DEMO2_pid"
        echo "===startAll success==="
        ;;
 
 stop)
        P_ID=`ps -ef | grep -w $DEMO1 | grep -v "grep" | awk ‘{print $2}‘`
        if [ "$P_ID" == "" ]; then
            echo "===DEMO1 process not exists or stop success"
        else
            kill -9 $P_ID
            echo "DEMO1 killed success"
        fi
        P_ID=`ps -ef | grep -w $DEMO2 | grep -v "grep" | awk ‘{print $2}‘`
        if [ "$P_ID" == "" ]; then
            echo "===DEMO2 process not exists or stop success"
        else
            kill -9 $P_ID
            echo "DEMO2 killed success"
        fi
 
        echo "===stop success==="
        ;;   
 
restart)
        $0 stop
        sleep 2
        $0 start
        echo "===restart success==="
        ;;   
esac    
exit 0
View Code

 

执行命令报错:

技术图片

 

 

后查找原因:

发现是win系统文件上传到linux默认加字符,使用命令执行语句:

sed -i ‘s/\r$//‘ 【名字】.sh

再次启动:

技术图片

 

 成功。

 

linux批量启动jar包

标签:close   查找   开始   open   ima   原因   win   code   else   

原文地址:https://www.cnblogs.com/cjll/p/13724050.html


评论


亲,登录后才可以留言!