主页 > 知识库 > Shell实现判断进程是否存在并重新启动脚本分享

Shell实现判断进程是否存在并重新启动脚本分享

热门标签:网站排名优化 呼叫中心市场需求 地方门户网站 服务外包 铁路电话系统 AI电销 百度竞价排名 Linux服务器

简洁版:

#! /bin/bash
# author caoxin
# time 2012-10-10 
# program : 判断进行是否存在,并重新启动


function check(){
  count=`ps -ef |grep $1 |grep -v "grep" |wc -l`
  #echo $count
  if [ 0 == $count ];then
    nohup python /runscript/working/$1 
  fi
}

check behaviors.py

详细版:

#!/bin/bash
#

#调用关闭jboss进程脚本
stopMethodServer.sh

#打印出当前的jboss进程:grep jboss查询的jboss进程,grep -v "grep" 去掉grep进程
jmsThread=`ps -ef | grep gdms | grep jboss | grep -v "grep"`
echo $jmsThread

#查询jboss进程个数:wc -l 返回行数
count=`ps -ef | grep gdms | grep jboss | grep -v "grep" | wc -l`
echo $count

sec=7
#开始一个循环,以判断进程是否关闭

for var in 1 2
do
 if [ $count -gt 0 ]; then
  #若进程还未关闭,则脚本sleep几秒
  echo sleep $sec second the $var time, the JMS thread is still alive
  sleep $sec
 else
  #若进程已经关闭,则跳出循环
  echo "break"
  break
 fi
done

#if [ $count -eq 0 ]; then
# echo "nohup startMethodServer.sh "
# nohup startMethodServer.sh 
#else
# echo "It's better to check the thread!!!"
#fi

#调用启动脚本
nohup startMethodServer.sh 
您可能感兴趣的文章:
  • Shell脚本判断Apache进程是否存在
  • Linux Shell中判断进程是否存在的代码
  • Shell 批量进程判断是否存在

标签:黄山 湘潭 仙桃 兰州 崇左 铜川 衡水 湖南

巨人网络通讯声明:本文标题《Shell实现判断进程是否存在并重新启动脚本分享》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266