点击(此处)折叠或打开
- #!/bin/bash
- ##
- # check listeners
- #
- LOGFILE=$HOME/dbadmin/logs/lsnr_check_`date +'%Y%m%d'`.log
- exec 3>&1 4>&2
- exec 1>>$LOGFILE 2>&1
- echo "Start: `date +%Y%m%d%H%M%S`"
- pr_stat()
- {
- ps -ef |grep tns
- ps -elf |grep $1 |grep -v grep
- pmap -x $1
- pflags $1
- }
- LISTENER_LIST=`sed -n 's/^SID_LIST_\(.*\)[ ]*=/\1/p' $TNS_ADMIN/listener.ora |tr "[A-Z]" "[a-z]"`
- TMPFILE=/tmp/lsnr_check_$$.tmp
- for f in $LISTENER_LIST; do
- echo -n "checking listener $f ..."
- [ -f $TMPFILE ] && rm -f $TMPFILE
- echo 'this is a line' >$TMPFILE
- #`tnsping $f |grep OK >>$TMPFILE &`
- `lsnrctl status $f |tail -1 |grep "successfully">>$TMPFILE &`
- sleep 3
- #test `cut -c1,2 $TMPFILE |grep OK`
- test "`grep successfully $TMPFILE`"
- if (($? != 0)); then
- echo "FAILED"
- pid=`ps -ef |grep tnslsnr |grep -i $f |grep -v grep |awk '{print $2}'`
- if [ "X$pid" != "X" ]; then
- pr_stat $pid
- echo -n "kill process $pid ..."
- kill -9 $pid
- if [ $? = 0 ]; then
- echo "stopped"
- else
- echo "Unable to stop tnslsnr"
- fi
- sleep 3
- else
- echo "tnslsnr not started"
- fi
- echo -n "starting listener $f ..."
- lsnrctl start $f
- echo "started"
- else
- echo "OK"
- fi
- [ -f $TMPFILE ] && rm -f $TMPFILE
- done
- echo "End: `date +%Y%m%d%H%M%S`"
- echo
- exec 1>&3 3>&-
- exec 2>&4 4>&-
- exit 0