建立一个守护进程:
#! /bin/sh
PRO_NAME=./xxxx.sh
while true ; do
#用ps获取$PRO_NAME进程数量
echo ‘‘> nohup.out
NUM=`ps aux | grep -w ${PRO_NAME} | grep -v grep |wc -l`
#echo $NUM
#少于1,重启进程
if [ "${NUM}" -lt "1" ];then
echo "${PRO_NAME} was killed"
${PRO_NAME} -d
#大于1,杀掉所有进程,重启
elif [ "${NUM}" -gt "1" ];then
echo "more than 1 ${PRO_NAME},killall ${PRO_NAME}"
killall -9 $PRO_NAME
${PRO_NAME} -d
fi
#kill僵尸进程
NUM_STAT=`ps aux | grep -w ${PRO_NAME} | grep T | grep -v grep | wc -l`
if [ "${NUM_STAT}" -gt "0" ];then
killall -9 ${PRO_NAME}
${PRO_NAME} -d
fi
sleep 5s
done
exit 0
建立一个重启DB的脚本(仅限rac使用),纯粹为方便:
#!/bin/bash
if [ $1 ]
then
{
db_name=$1
srvctl stop database -d $db_name -o abort
num=`ps -ef|grep -i smon_|grep -v grep|grep -v -i asm|awk ‘{print $2}‘ `
if [ ! $num ]
then
echo "database restart........."
fi
while [ "$num" ]
do
sleep 1
num=`ps -ef|grep -i smon_|grep -v grep|grep -v -i asm |awk ‘{ print $2 }‘`
echo "database not shutdown ,please check!"
done
srvctl start database -d $1
num=`ps -ef|grep -i smon_|grep -v grep|grep -v -i asm |awk ‘{ print $2 } ‘`
if [ $num ]
then
echo "database starting "
fi
if [ ! -n "$num" ]
then
echo "start fail"
else
echo "start sucessfully"
fi
}
else
echo "No parameter ,eg: ./stop_db.sh dbname"
fi
原文地址:http://blog.51cto.com/snowhill/2086230
时间: 2024-10-09 03:38:23