<?xml version="1.0" encoding="UTF-8"?><!-- generator="bbPress" -->

<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
>

<channel>
<title>AskDBA.org Forum &#187; Topic: DB and Listener availability monitoring script</title>
<link>http://www.forum.askdba.org/</link>
<description>Forum for Oracle DBA&#039;s</description>
<language>en</language>
<pubDate>Sun, 12 Feb 2012 10:32:52 +0000</pubDate>

<item>
<title>Anonymous on "DB and Listener availability monitoring script"</title>
<link>http://www.forum.askdba.org/topic/db-and-listener-availability-script#post-158</link>
<pubDate>Sat, 12 Jun 2010 11:04:23 +0000</pubDate>
<dc:creator>Anonymous</dc:creator>
<guid isPermaLink="false">158@http://www.forum.askdba.org/</guid>
<description>&#60;p&#62;Nice thing shared but i cant recognize the instruction of&#34;Oracle wallet&#34; to store password will you make this clear to me that how to store password??
&#60;/p&#62;</description>
</item>
<item>
<title>Amit Bansal on "DB and Listener availability monitoring script"</title>
<link>http://www.forum.askdba.org/topic/db-and-listener-availability-script#post-134</link>
<pubDate>Thu, 11 Mar 2010 06:13:39 +0000</pubDate>
<dc:creator>Amit Bansal</dc:creator>
<guid isPermaLink="false">134@http://www.forum.askdba.org/</guid>
<description>&#60;p&#62;Hi,&#60;/p&#62;
&#60;p&#62;Find below a simple script to monitor db and listener. It uses utl_mail procedure to connect to a mailserver db and send a mail in case of failure.&#60;br /&#62;
You can also use mailx function to send mail.&#60;br /&#62;
I have hard-coded password , but you can also use Oracle wallet to store password. Refer to my blog post &#60;a href=&#34;http://askdba.org/weblog/2009/09/using-oracle-wallet-to-execute-shell-scriptcron-without-hard-coded-oracle-database-password/&#34;&#62; here &#60;/a&#62; for details&#60;/p&#62;
&#60;p&#62;You need to pass ORACLE_SID as parameter. So to schedule a cron to check every 10 mins, you need to specify like below&#60;/p&#62;
&#60;pre&#62;
00,10,20,30,40,50 * * * * sh /home/oracle/monitor/db_check.sh orcl
&#60;/pre&#62;
&#60;p&#62;Find below the script. Any suggestions/improvements are welcome&#60;/p&#62;
&#60;pre&#62;

###################################################################
## Check Database Availability
###################################################################
##########Env Variables #############
export DBA_MAIL1='amit.bansal@askdba.org'
export DBA_MAIL2='saurabh.sood@askdba.org'
export ORACLE_HOME=/oracle/ora_db
export TNS_ADMIN=$ORACLE_HOME/network/admin
export BASE_DIR=/home/oracle/monitor
export ORACLE_SID=$1
export LOG_FILE=$BASE_DIR/$ORACLE_SID.log
export PATH=$ORACLE_HOME/bin:$PATH
export machinename=&#60;code&#62;hostname&#60;/code&#62;
###################################
cd $BASE_DIR
echo &#34;&#60;code&#62;date&#60;/code&#62;   &#34; &#38;gt; $LOG_FILE
echo  &#34;Oracle Database(s) Status &#60;code&#62;hostname&#60;/code&#62; :\n&#34; &#38;gt;&#38;gt;  $LOG_FILE
db_cnt=&#60;code&#62;ps -ef&#124;grep pmon&#124;grep $ORACLE_SID&#124;wc -l&#60;/code&#62;
if [ $db_cnt -gt 0 ]; then
        echo &#34;$ORACLE_SID is Up&#34; &#38;gt;&#38;gt; $LOG_FILE
else
        echo &#34;$ORACLE_SID is Down&#34; &#38;gt;&#38;gt; $LOG_FILE
$ORACLE_HOME/bin/sqlplus -s &#34;system@maildb/oracle123&#34; &#38;lt;&#38;lt;EOF  &#38;gt;&#38;gt; $LOG_FILE
        alter session SET smtp_out_server = 'mailserv:100';
        BEGIN
        UTL_MAIL.send(
 sender =&#38;gt; 'webmaster@askdba.org'
 ,recipients =&#38;gt; '${DBA_MAIL1}'
,cc =&#38;gt; '${DBA_MAIL2}'
 ,subject =&#38;gt; '${ORACLE_SID} is down on ${machinename}'
 ,message =&#38;gt; '${ORACLE_SID} is Down on ${machinename}'
 ,mime_type =&#38;gt; 'text/plain; charset=us-ascii'
 ,priority =&#38;gt; 3);
 END;
/
exit
EOF
fi

lsn_cnt=&#60;code&#62;ps -ef&#124;grep tnslsnr&#124;grep oracle&#124;grep -v grep&#124;wc -l&#60;/code&#62;
if [ $lsn_cnt -gt 0 ]; then
        echo &#34;Listener is up&#34; &#38;gt;&#38;gt;$LOG_FILE
else
echo &#34;Listener is down&#34; &#38;gt;&#38;gt;$LOG_FILE
$ORACLE_HOME/bin/sqlplus -s &#34;system@maildb/oracle123&#34; &#38;lt;&#38;lt;EOF  &#38;gt;&#38;gt; $LOG_FILE
        alter session SET smtp_out_server = 'mailserv:100';
        BEGIN
         UTL_MAIL.send(
 sender =&#38;gt; 'webmaster@askdba.org'
,recipients =&#38;gt; '${DBA_MAIL1}'
,cc =&#38;gt; '${DBA_MAIL2}'
 ,subject =&#38;gt; 'Listener is down on ${machinename}'
 ,message =&#38;gt; 'Listener is Down on ${machinename}'
 ,mime_type =&#38;gt; 'text; charset=us-ascii'
 ,priority =&#38;gt; 3);
 END;
/
exit
EOF
fi
&#60;/pre&#62;</description>
</item>

</channel>
</rss>

