先附上命令语句
#!/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
执行命令报错:
后查找原因:
发现是win系统文件上传到linux默认加字符,使用命令执行语句:
sed -i 's/ $//' 【名字】.sh
再次启动:
成功。