springboot执⾏linux脚本,shell脚本执⾏springbootjar 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)
linux循环执行命令脚本$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环境下编码不⼀致导致的
解决⽅法问度娘
实在不⾏就⼿动输⼀遍