To establish a daemon process:
#! /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
Create a script that restarts db (for RAC use only), purely for convenience:
#!/bin/bashif [ $1 ]then{db_name=$1srvctl stop database -d $db_name -o abortnum=`ps -ef|grep -i smon_|grep -v grep|grep -v -i asm|awk ‘{print $2}‘ `if [ ! $num ]thenecho "database restart........."fiwhile [ "$num" ]dosleep 1num=`ps -ef|grep -i smon_|grep -v grep|grep -v -i asm |awk ‘{ print $2 }‘`echo "database not shutdown ,please check!" donesrvctl start database -d $1num=`ps -ef|grep -i smon_|grep -v grep|grep -v -i asm |awk ‘{ print $2 } ‘`if [ $num ]thenecho "database starting "fiif [ ! -n "$num" ]thenecho "start fail"elseecho "start sucessfully"fi}elseecho "No parameter ,eg: ./stop_db.sh dbname"fi
Linux Shell daemon/RAC Restart script