进程类监控,if套if循环

代码如下

#!/bin/bash


#this script is for check process

NUM_RE=`ps aux | grep new.py | grep -v grep | wc -l`


mdate=`date +%Y-%m-%d-%H:%M:%S`

cd $(dirname $0)
echo $NUM_RE

if [ "$NUM_RE" -eq "1" ];then
        echo "no check"
else
        nohup python new.py &
        #sleep 10
        NUM_RE=`ps aux | grep new.py | grep -v grep | wc -l`        #else启动程序以后发现上面的变量不生效,只好在重新定义一边
        echo $NUM_RE
        echo ------------------------
        echo $NUM_RE
        if [ "$NUM_RE" -eq "1" ];then
                echo $mdate SC-RE restart success!
                echo $NUM_RE
        else
                echo $mdate SC-RE restart failed!
        fi
fi

 

posted @ 2021-02-02 10:55  hanjianfei  阅读(88)  评论(0编辑  收藏  举报