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

#!/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

你可能感兴趣的:(一个监控进程的脚本,若进程异常重启进程)