因为是一个while(true)循环的jar包,所以在执行jar包的时候就一直卡在这里,不会执行后续的shell代码。
原代码如下:
#!/bin/bash
export JAVA_HOME=/home/agenttest/nicflow/jre
export WLDS_HOME=/home/agenttest/nicflow/iftopGetFlow
APP_HOME=/home/agenttest/nicflow/iftopGetFlow
TPIDS=0
checkpid(){
TPIDS=`ps -ef |grep "ip.jar" |grep -v grep | awk '{print $2}'`
}
start(){
checkpid
if [ "$TPIDS" = "" ];then
JAVA_CMD="java -jar ip.jar"
su -c "$JAVA_CMD"
sleep 2
checkpid
if [ "$TPIDS" = "" ];then
echo "ip.jar start failed."
else
echo "ip.jar start successfully. pids $TPIDS"
fi
exit
else
echo "ip.jar is running. No need to start!"
fi
}
stop(){
checkpid
if [ "$TPIDS" = "" ];then
echo "ip.jar is not running. No need to stop!"
else
kill -9 $TPIDS
sleep 2
checkpid
if [ "$TPIDS"