shell 脚本执行springboot jar

1.shell脚本

#!/bin/bash
# description: selenium service
#端口号,根据此端口号确定PID
PORT=9000
#jar包所在目录
HOME='/usr/local/selenium'
#查询出监听了port端口的TCP协议的程序
pid=`netstat -anp|grep $PORT|awk '{printf $7}'|cut -d/ -f1`
start(){
 echo "INFO: Starting selenium ..."
   if [ -n "$pid" ]; then
      echo "server already start,pid:$pid"
      return 0
   fi
   #进入命令所在目录
   cd $HOME
   #启动selenium服务
   java -jar $HOME/selenium-sever-standalone-2.53.1.jar -role hub -port 9000 >selenium.log 2>&1 &
   echo "start at port:$PORT"
}
stop(){
   if [ -z "$pid" ]; then
      echo "not find program on port:$PORT"
      return 0
   fi
   #结束程序
   kill -9 $pid
   rm -rf $pid
   while true
   do
        process=`netstat -anp|grep $PORT|awk '{printf $7}'|cut -d/ -f1`;
echo "process id is"+$process;
        if [ "$process"!="" ]; then
                sleep 1;
                echo "stopping ...";
        else
                echo "service selenium stop";
                break;
        fi
    done
}
status(){
   if [ -z "$pid" ]; then
      echo "not find program on port:$PORT"
   else
      echo "program id running,pid:$pid"
   fi
}
case $1 in
   start)
      start
   ;;
   stop)
      stop
   ;;
   restart)
      $0 stop
      sleep
      $0 start
   ;;
   status)
      status
   ;;
   *)
      echo "Usage: {start|stop|status}"
   ;;
esac
exit 0

2.在/etc/init.d文件夹下新建文件 cat>>filename

然后将上述shell脚本拷进去,然后执行service filename start/stop/status/restart

3.问题

直接从windows将脚本考到linux环境会运行不成功

因为windows与linux环境下编码不一致导致的

解决方法问度娘

实在不行就手动输一遍

转载于:https://my.oschina.net/u/4042489/blog/3018867

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值