sky's profileDBA日记PhotosBlogListsMore Tools Help
    11/9/2009

    检测listener挂起,并重启的脚本

    如果lsnr挂起(tnsping失败),则杀掉进程重启lsnr

    如果lsnr被手动关闭(tns进程不在),不会进行任何操作。

    echo `date`
    echo 'The old LSNR id is:'`ps -ef|grep tnslsnr|grep -v grep|awk '{print $2}'`

    RVALUE=`tnsping npmserver|grep OK|awk '{print $1}'|wc -l`
    echo 'OK found:' $RVALUE

    if  [ $RVALUE  != 0 ]
    then
            echo 'LSNR work fine! bye'
    fi

    if [ $RVALUE  = 0 ]
    then
        TNSCOUNT=`ps -ef|grep tnslsnr|grep -v grep|wc -l`
            if [ $TNSCOUNT != 0 ]
            then
                    echo 'Kill the old LSNR process,starting LSNR...'
                    ps -ef|grep tnslsnr|grep -v grep|awk '{print $2}'|xargs kill -9
                    lsnrctl start
                    echo 'The new LSNR id is:' `ps -ef|grep tnslsnr|grep -v grep|awk '{print $2}'`
            fi

            if [ $TNSCOUNT = 0 ]
            then
                    echo 'LSNR not running,try lsnrctl start if needed!'
            fi
    fi
    echo '########################################'                                      
    echo