编写可以监控oracle监听器是否启动的shell脚本

来源:互联网 发布:zara淘宝 编辑:程序博客网 时间:2024/05/16 13:57

在oracle目录下创建一个监听文件:

[root@ocp ~]# cd /home/oracle
[root@ocp oracle]# touch chklistener_1.sh
[root@ocp oracle]# vi chklistener_1.sh

进入编辑界面并添加以下文本:

# !/bin/bash
./home/oracle/.bash_profile
declare -i n_lsnr
n_lsnr=ps-ef | grep listener | grep -v grep |wc -l
if[$n_lsnr=0];then
lsnrctl start> /dev/null
mail 
shunmin@126.com -s "listener is down, and restarted."
fi

邮箱换成自己的邮箱 用来接收提示信息,:wq保存退出

解析:

脚本第四行:使用ps及grep命令查询当前正在进行的listener进程个数,并赋值给n_lsnr变量

脚本第五行:如果监听进程个数为0则启动listener进程并屏蔽启动时的输出信息,同时发出告警邮件

以上脚本很简陋,如果重启监听时发生错误,邮件标题并不能反映出这种情况,下面的代码会更完善一些:

[root@ocp oracle]# touch chklistener_2.sh
[root@ocp oracle]# vi chklistener_2.sh

# !/bin/bash

./home/oracle/.bash_profile

tempfile=/oracle/admin/$ORACLE_SID/tempfile.lis

lsnrctl status>$tempfile

if[$?!=0]

then

echo"">>$tempfile

echo"---------------">>$tempfile

echo"">>$tempfile

date>>$tempfile

echo "listener is down,restarting it again">>$tempfile

lsnrctl start>>$tempfile

if[$?=0]

then

mail shunmin@163.com -s"listener is restarted"<$tempfile

else

mail shunmin@163.com -s"listener is down,restarting failed"<$tempfile

 fi

fi


rm -f $tempfile


以上脚本可以判断启动监听时是否出错 发邮件通知DBA



0 0
原创粉丝点击