parity 自动重启脚本

2020-08-04  本文已影响0人  xun2019

#!/bin/bash
PROCESS='hparity'
LOG=mem.txt
SETMEM=16.5
ps -ef | grep $PROCESS | grep -v grep
if [ $? -ne 0 ]
then
        echo "start process......"
        sh start.sh
else
        echo "runing......"
fi

#过滤出需要的进程ID
PID=$(ps -ef | grep $PROCESS | grep -v 'grep' | awk '{print $2;}')

while true
do
    MEM=$(cat /proc/$PID/status | grep RSS | awk '{print $2;}')
    starttime=$(date +%Y-%m-%d\ %H:%M:%S)
    echo "$starttime  $MEM" >>mem.txt

    GMEM=$(printf "%.5f" `echo "scale=5;$MEM/1024/1024"|bc`)
    echo "$GMEM"
    if [ $(echo "$GMEM > $SETMEM"|bc) = 1 ];then
        echo "MEM great than set mem $SETMEM ,restart $PROCESS"
        kill $PID
    fi

    sleep 10
    PID=$(ps -ef | grep $PROCESS | grep -v 'grep' | awk '{print $2;}')
    if [ "$PID" == "" ];then
        echo "start $PROCESS ..."
        sh start.sh        
    fi  


done

上一篇 下一篇

猜你喜欢

热点阅读