#!/bin/sh
basepath=$(cd `dirname $0`; pwd)
while true
do
procnum=`ps -ef|grep "ppss.out"|grep -v grep|wc -l`
if [ $procnum -eq 0 ]
then
#start service
cd $basepath
./ppss.out &
echo `date +%Y-%m-%d` `date +%H:%M:%S` "restart srevice" >>$basepath/shell.log
fi
sleep 1
done
#!/bin/sh
counts=0
loops=3
while true
do
ps -ef | grep xxx_server.out | grep -v grep
a=$?
b=1
if [ "$a" -eq "$b" ]
then
if [ $counts -ge $loops ]
then
nohup ./xxx_server.out >xxx_server.log 2>&1 &
counts=0
echo "process has been restarted!"
else
counts=$(($counts+1))
echo "process exited,counter plus +1 !"
fi
else
#echo "process already started!"
counts=0
fi
sleep 10
done
后台执行 nohup ./watch_dog.sh &