Shell实现判断进程是否存在并重新启动脚本
Shell实现判断进程是否存在并重新启动脚本 - superbfly的专栏 - CSDN博客 https://blog.csdn.net/superbfly/article/details/52513765
#! /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 &
#!/bin/bash
while [ 1 ]
do
#打印出当前的jboss进程:grep jboss查询的jboss进程,grep -v "grep" 去掉grep进程
jmsThread=`ps -ef | grep testServer | grep -v "grep"`
# echo $jmsThread
#查询jboss进程个数:wc -l 返回行数
count=`ps -ef | grep testServer | grep -v "grep" | wc -l`
# echo $count
if [ $count -eq 0 ]; then
s="cd /root/testServer/bin;nohup python testServer.py start"
eval $s
# echo "bad!"
# else
# echo "ok"
fi
done
Shell实现判断进程是否存在并重新启动脚本的更多相关文章
- Shell脚本监控Linux某个后台进程,当进程死掉后重新启动服务,以httpd为例
Shell脚本如下: vim monitor.sh #!/bin/bash while true # 无限循环 flag=`ps -aux |grep "httpd" |grep ...
- systemctl可以实现nginx进程挂了之后自动重新启动
接 2018年7月31日的那篇: vim /lib/systemd/system/nginx.service [Service]Restart=alwaysRestartSec=1Type=forki ...
- INNO setup安装卸载钱判断进程中是否在运行总结
1.安装前判断进程中是否有程序在运行. [files] ; 安装前判断进程,dll文件放在inno的安装目录中Source: compiler:psvince.dll; Flags: dontcopy ...
- 在Shell里面判断字符串是否为空
在Shell里面判断字符串是否为空 分类: Linux shell2011-12-28 23:18 15371人阅读 评论(0) 收藏 举报 shell 主要有以下几种方法: echo “$str” ...
- inno setup 安装前判断进程是否存在,以及停止相应进程<转>
打包的时候遇到了这样的需求:假似用户都是傻瓜 式操作,如果更新安装程序的时候,之前的老程序还在运行这个时候如果你去提示让用户吧老程序手动退掉也不现实. 所以当遇到这种 ...
- linux脚本-判断进程是否存在,从而可以做预警处理..
count=`ps -ef | grep Seeyon | grep -v "grep" | wc -l` echo $count if [ $count -gt 0 ]; the ...
- DOS中判断进程是否存在的方法
这里分享的主要是通过批处理中先判断进程是否存在,然后再做出操作的实现代码,需要的朋友可以参考下 检测进程是否存在,并做出预定动作. tasklist /nh>d:\tddown~1\1.tx ...
- shell的父子进程
2017年1月11日, 星期三 shell的父子进程 启动/执行方式: 当前shell: #!/bin/bash 必须行首 ...
- shell if判断中常用的a-z表达式含义
shell if判断中常用的a-z表达式含义 可通过在在linux中man test命令查看下列参数的详细用法 [ -a FILE ] 如果 FILE 存在则为真. [ -b FILE ] 如果 ...
随机推荐
- 配置Windows Server 2008/2012/2016允许2个用户同时远程桌面
Windows Server 系列服务器默认情况下只能支持一个用户远程,如果第二个人远程上去之后会直接把前面一个登录用户踢掉.在日常工作中如果有多个人需要同时远程过去工作,会很不方面. 网上很多教程讲 ...
- CentOS 7 配置HTTPS加密访问SVN
上一篇文章已经介绍了如何在CentOS7环境下安装SVN并整合HTTP访问 http://www.cnblogs.com/fjping0606/p/7581093.html 那么本文则介绍如何添加HT ...
- 译: 1. RabbitMQ Spring AMQP 之 Hello World
本文是译文,原文请访问:http://www.rabbitmq.com/tutorials/tutorial-one-spring-amqp.html RabbitMQ 是一个Brocker (消息队 ...
- List 比较大小
List<Player> lst = new List<Player>(); lst.Add()); lst.Add()); lst.Add()); lst.Add()); l ...
- Ubuntu python3 安装pip
python2:sudo apt-get install python-pip python3:sudo apt-get install python3-pip 切换python2和python3的版 ...
- MXNET:深度学习计算-自定义层
虽然 Gluon 提供了大量常用的层,但有时候我们依然希望自定义层.本节将介绍如何使用 NDArray 来自定义一个 Gluon 的层,从而以后可以被重复调用. 不含模型参数的自定义层 我们先介绍如何 ...
- Entlib DAAB映射枚举类型
1. IRowMapper<UserDto> addressMapper = MapBuilder<UserDto> .MapAllProperties() .Map(p =& ...
- CentOS5.x、CentOS6.x 使用NFS及mount实现两台服务器间目录共享
一.环境介绍: 服务器:centos 192.168.1.225 客户端:centos 192.168.1.226 二.安装: NFS的安装配置:centos 5 : portmap:实现RPC(协议 ...
- Envoy 代替nginx https://www.jianshu.com/p/0a1f67b42fdb
官方文档: https://www.envoyproxy.io/docs1.6.0版官方文档: https://www.envoyproxy.io/docs/envoy/v1.6.0/ 一. 编译和安 ...
- hdoj:2031
#include <iostream> #include <string> using namespace std; int main() { int N,R; string ...