linux 守护 脚本,linux中java执行脚本守护脚本
#/bin/bashwhile true;docount=`ps -ef | grep test.jar | grep -v grep|wc -l`if [ ${count} -lt 1 ]; thennohup java -jar xxx.jar >log.out 2>&1 &elseecho “process is running”fisleep 3doneLin.
#/bin/bash
while true;
do
count=`ps -ef | grep test.jar | grep -v grep|wc -l`
if [ ${count} -lt 1 ]; then
nohup java -jar xxx.jar >log.out 2>&1 &
else
echo “process is running”
fi
sleep 3
done
Linux Shell脚本:自动读取pid并关闭进程
查询进程信息
ps -ef|grep elasticsearch

过滤掉grep进程
ps -ef|grep elasticsearch|grep -v grep

提取pid(awk以空格分割,显示第二个变量即为pid)
ps -ef|grep elasticsearch|grep -v grep|awk ‘{print $2}’

根据pid kill掉该进程
完整脚本如下所示


Share this:
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)