一起学习网 一起学习网


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

网络编程 Shell实现判断进程是否存在并重新启动脚本分享 06-22

简洁版:

#! /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脚本编程之if语句学习笔记
我不是研究linux下的东西的,所以这里只对shell脚本的用法做一个介绍,把我自己在使用过程中出现的问题记录下来,同时也是写下一些shell脚本语法的

shell脚本编程之循环语句学习笔记
本篇博客很简单,看一下shell编程使用到的循环语句,包括for循环,while循环,until循环,for后边跟一个变量,然后是一个集合,将集合中的东西赋给这

shell脚本编程之case语句学习笔记
case语句是用来实现多个if..else的功能的,但是用法上有些不同,学过其他语言的人都知道,case中要对变量进行匹配,如果有一个匹配成功的话就执行相


编辑:一起学习网

标签:脚本,进程,语句,学习笔记,变量