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環境下編碼不一致導致的
解決方法問度娘
實在不