一个监控进程的脚本,若进程异常重启进程

#!/bin/sh
echo "Current DIR is " $PWD
while [ 1 ]
do
serverpid=`ps -ef|grep 进程名|grep -v grep|awk '{print $2}'`
if [ "$serverpid" ]
then
echo "进程名 is running,pid is " $serverpid
#kill -9 $serverpid
else
echo "进程名 is down ,now starting ..."
dt=`date +%F`
nohup 进程 2>>/data/socket/$dt"_ad_error.log" 1>>/data/socket/$dt"_ad_access.log" &
fi
sleep 5
done

posted @ 2017-09-12 09:06  Oops!#  阅读(568)  评论(0编辑  收藏  举报