linux shell守护进程/ rac重启脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux shell守护进程/ rac重启脚本相关的知识,希望对你有一定的参考价值。
建立一个守护进程:
#! /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
以上是关于linux shell守护进程/ rac重启脚本的主要内容,如果未能解决你的问题,请参考以下文章