日期:2014-05-16  浏览次数:20595 次

大侠们帮我解释下这个.sh文件中的命令
#!/bin/bash

#cd /home/sis/EnvDataCenterCollection
exename=Enserver.jar
pid=`ps ax|grep ${exename}|grep -v grep|awk '{print $1}'`
if [[ $pid ]]
then
echo 'find pid is '$pid
kill -9 $pid
echo "killed $pid over"
else
echo "There is no process running....."
fi
echo "start new process...."
nohup java -jar ${exename}>>./nohup.out 2>&1 &
ps -ef |grep '${exename}'|grep -v grep
echo 'restart successfully'
没怎么接触过linux命令。请大侠们帮我解释解释。


------解决方案--------------------
#!/bin/bash
#cd /home/sis/EnvDataCenterCollection
exename=Enserver.jar 变量,把Enserver.jar赋值给exename
pid=`ps ax|grep ${exename}|grep -v grep|awk '{print $1}'` 得到包含Enserver.jar的进程的pid
if [[ $pid ]]
then
echo 'find pid is '$pid
kill -9 $pid 存在包含Enserver.jar的进程的pid就把这个进程杀死
echo "killed $pid over"
else
echo "There is no process running....."
fi
echo "start new process...."
nohup java -jar ${exename}>>./nohup.out 2>&1 & 开始新的进程,后台运行,
ps -ef |grep '${exename}'|grep -v grep 进程是否存活,即查看新进程是否开启
echo 'restart successfully'


上面那段shell就是用于重启Enserver.jar这个应用的