Java 在 Linux启停Shell脚本

JavaLinux启停Shell脚本

#!/bin/bash
APP_NAME="opserver-base-0.0.1-SNAPSHOT.jar"
CONFIG="test"
case $1 in
    start)
        nohup java -jar ${APP_NAME} --spring.profiles.active=${CONFIG} >gdOp${CONFIG}Log.txt 2>&1 &
        echo ${APP_NAME} start!
        ;;
    stop)
        ps -ef| grep ${APP_NAME} |grep -v grep |awk '{print $2}'  | sed -e "s/^/kill -9 /g" | sh -
        echo ${APP_NAME} stop!
        ;;
    restart)
        bash "$0" stop
        sleep 3
        bash "$0" start
        ;;
    status)
        ps -aux | grep ${APP_NAME} | grep -v 'grep'
        ;;
    log)
        case $2 in
            nohup)
                tail -f gdOp${CONFIG}Log.txt
                ;;
            *)
              echo "Example:bash services.sh log nohup" ;;
        esac
            ;;
    *)
        echo "Example:bash services.sh [start|stop|restart|status]" ;;
esac

解决:

1.删除shell脚本 /r

sed -i 's/\r//' 文件名

2.tab制表符转空格

猜你喜欢

转载自www.cnblogs.com/tangshengwei/p/12937783.html